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


are both set to array() in the receiving url

$json_arguments is set to soemething like


I can’t see anything wrong with it.



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.
$json = json_decode($jsonStr);

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