Jump to content

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


Go to solution Solved by QuickOldCar,

Recommended Posts

$post='{"cart_items":[{"configuration":{"price":100,"recharge_number":"9999999999"},"product_id":"999","qty":1}]}';

i try this n reslut was :There are no valid items in cart:   help me plz

Edited by ShivaGupta

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);
Edited by ShivaGupta
  • Solution

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));
  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.