解压缩使用POST CURL发送的数据 [英] unpack data sent using POST CURL

查看:103
本文介绍了解压缩使用POST CURL发送的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用curl命令接收正在发布的数据。数据是URLify以便建立http查询。使用curl发送数据的命令是:

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);

现在如何解压缩使用curl build查询发送的值。我试图像这样从curl发送值,但我没有得到值发布,而是给了我1和0:

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;


推荐答案

更改:

echo"data:= "+$_product_name+$_price+$_quantity+$_seller;

收件人:

echo "data:= " . $_product_name . $_price . $_quantity . $_seller;

为什么?如果您在PHP中将+与字符串一起使用,它们将被解释为0或1并以这种方式添加。

Why? If you use + with strings in PHP, they get interpreted as 0 or 1 and added that way.

这篇关于解压缩使用POST CURL发送的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆