I am trying to receive the data being posted using the curl commands. Data is URLify in order to build http query. The commands for data being sent using curl are :
$data=array(
'product_name' =>'Television',
'price' => 1000,
'quantity' => 10,
'seller' =>'XYZ Traders'
);
$DT=http_build_query($data);
echo($DT);
$url = 'http://localhost/API2/products';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$DT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response_json = curl_exec($ch);
echo $response_json;
curl_close($ch);
Now how to unpack the values being sent using curl build query. I am trying to get the values sent from curl like this but i don't get the values posted rather it gives me 1's and zero's:
$_product_name=$_POST["product_name"];
$_price=$_POST["price"];
$_quantity=$_POST["quantity"];
$_seller=$_POST["seller"];
echo"data:= "+$_product_name+$_price+$_quantity+$_seller;
See Question&Answers more detail:os