Reputation: 16897
I have a webservice..just say example.com. I need to do a HTTP POST to call this web service in PHP and send data to this web service. The data I'm posting is from a form so is available in variables. I have read that this might be a way to do it, but I'm not sure, so any pointers in the right direction would be appreciated.
$service_url = 'http://example.com/rest/user';
$curl = curl_init($service_url);
$curl_post_data = array(
$compName,
$package,
$email1,
$telephone1
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
Upvotes: 1
Views: 1116
Reputation: 349
Yep that should do the trick. Just execute that curl handle:
$returnData = curl_exec($curl);
Do note that when you're using an array as your POSTFIELDS and not a string "key=val&key2=val..." it will set it to multipart/form-data and not application/x-www-form-urlencoded. I know I've had troubles with that my self at some point.
Upvotes: 2