Curl not posting

    $ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
$certificate_location = "/etc/ssl/certs/ca-certificates.crt"; 
curl_setopt($ch, CURLOPT_CAINFO, $certificate_location);
curl_setopt($ch, CURLOPT_CAPATH, $certificate_location);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($auth_request, CURLOPT_HEADER, false);	
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_arguments);

// Set HTTP Header for POST request 
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
		"Content-Type: application/json"
	));

//execute post
$result = curl_exec($ch);

Isn’t posting anything to $url

print_r($_REQUEST);
print_r($_POST);

are both set to array() in the receiving url

$json_arguments is set to soemething like

{“api_user_id”:“aa”,“api_password”:“bb”,“api_signature”:“cc”,“type”:“GetPropertyTypes”}

I can’t see anything wrong with it.

Thanks

JSON != POST

so there’s nothing to parse into $_POST for PHP. You have to read the raw request from php://input like from a file

I was just going to post that I have I have just tried as well but you beat me

jsonStr = file_get_contents(“php://input”); //read the HTTP body.
print_r($json);
$json = json_decode($jsonStr);
print_r($json);

That isn’t finding anything either

The url does a redirect so could that be it?

I am confused as I have tried changing the array to an ordinary array and posting that using

foreach($data as $key=>$value) {
$post_data[$key] = $value;
}

but $data and $post_data are both json arrays

I needed to add

curl_setopt($ch, CURLOPT_POSTREDIR, 3);

It is now posting :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service