mosuncoker
asked on
What may be wrong with my php http post function
Hello,
I have a php file that sends content to a server. Please see the code snippet below. The curl.exec() wont work except i append the api params to the posted url. It seems the code works as a Get method and not Post.
See code :
I have a php file that sends content to a server. Please see the code snippet below. The curl.exec() wont work except i append the api params to the posted url. It seems the code works as a Get method and not Post.
See code :
$sender = $_POST['sender'];
$message = $_POST['message'];
//addressGroup
$r_source = $_POST['r_source'];
if($r_source=="0"){
$receiver = $_POST['receiver'];
}
else{
// do something
}
$request = "";
$username7 = $_SESSION['username'];
$password7 = $_SESSION['password'];
$param["username"] = $username7; //the account username provided by gateway provider
$param["filenumber"] = $receiver; //the recipient of the message
$param["senderid"] = $sender; //the message sender
$param["message"] = $message; //the message that will be sent
foreach($param as $key=>$val){
$request.= $key."=".urlencode($val);
$request.= "&";
}
$request = substr($request, 0, strlen($request)-1);
$url = "http://xyz.com/send.ashx?".$request; //the gateway's interface provided by the gateway provider
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
ASKER
It works as get here.
Could you give me a code snippet for php http post
Could you give me a code snippet for php http post
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window