I have two sites on the same server:
api.mysite.com
john.mysite.com
On my API site, I have a service that accepts a POSTed json array. In my john.mysite.com site I’m calling the service and posting it using:
$info['id'] ="oo_".uniqid();
$info['version'] ="5";
$url = "http://api.mysite.com/services/addclient";
$posted_fields = json_encode($info);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
echo $result;
When this is called, I’m not getting anything posted to the webservice. I’ve gone into that code and dumped out $_POST and it’s empty. Why isn’t the curl sending the data via POST?
Thanks for any help!
One problem is that you are
json_encodeing the data instead of form encoding it.Another is that
$infomight not be initialized.Another is that you typo’d
$postfieldson line 9.Try: