Jump to content

Sending cURL POST data as "Content-Type: application/json"


MySQL_Narb

Recommended Posts

$data = http_build_query(array('action' => 'vote', 'id' => $id, 'ajax_module' => 'tracking', 'module_type' => 'public', 'dir' => '1'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL, 'http://www.REMOVED.com/ajax.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

 

Is this how I can send POST data, but change the HTTP headers in the request to:

Content-Type: application/json

 

Thanks!

$data = http_build_query(array('action' => 'vote', 'id' => $id, 'ajax_module' => 'tracking', 'module_type' => 'public', 'dir' => '1'));

That's not JSON. Have you first changed it to send JSON data?

$data = http_build_query(array('action' => 'vote', 'id' => $id, 'ajax_module' => 'tracking', 'module_type' => 'public', 'dir' => '1'));

That's not JSON. Have you first changed it to send JSON data?

 

I did have the array wrapped in json_encode(); but I'm pretty sure that didn't work (http_build_query returned an error about accepting only objects and arrays).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.