Jump to content

how to post this array post data in curl using php .


ShivaGupta

Recommended Posts

Im trying to send a json array to a php post request.

 

{"cart_items":[{"configuration":{"price":100,"recharge_number":"9999999999"},"product_id":"999","qty":1}]}

 

but here i dont know how to send in php plz help me with $fields .its argent

url_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded","Content-Type: application/json; charset=utf-8"));

curl_setopt($ch, CURLOPT_USERAGENT, $agent ); 
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$oone=curl_exec($ch);

json_decode()

 

Once you have them in an array

$fields = http_build_query($json_array); //builds the query

this is the count of how many post fields are sending

curl_setopt($ch, CURLOPT_POST, count($fields));

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.