【问题标题】:$_POST array is null while using PUT in cURL在 cURL 中使用 PUT 时 $_POST 数组为空
【发布时间】:2016-07-05 11:24:17
【问题描述】:

我有这个代码:

$curl = curl_init("localhost/curlexample/index.php/users/$id");
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $temp);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
echo $result;

我正在尝试使用 $_POST 超级全局变量访问 $temp 中的变量,但它返回 null。我想使用 cURL 执行 PUT 操作,我试图使用 CURLOPT_CUSTOMREQUEST 来实现。现在,每当我从代码中删除 CURLOPT_CUSTOMREQUEST 时,它都可以正常工作。否则,$_POST 返回 null。

我做错了什么?或者是否有其他方法来执行 PUT?

我以此作为参考:https://developer.sugarcrm.com/2013/08/30/doing-put-and-delete-with-curl-in-php/

【问题讨论】:

标签: php post curl put


【解决方案1】:

看看this post。您需要使用php://input 访问数据,如下所示:

parse_str(file_get_contents("php://input"), $post_vars); // $post_vars will get populated with the PUT variables.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 2017-01-07
    • 2016-06-20
    • 1970-01-01
    相关资源
    最近更新 更多