Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP curl请求中将查询参数放入服务器_Php_Curl_Put - Fatal编程技术网

在PHP curl请求中将查询参数放入服务器

在PHP curl请求中将查询参数放入服务器,php,curl,put,Php,Curl,Put,我试图使用PHP和curl发送一个PUT请求,但我的查询参数似乎没有发送到API。日志验证请求是否作为PUT传入,但参数没有发出请求。我遵循了在internet上找到的每个示例,这些示例描述了如何构建查询参数手动构建并使用http_build_query函数。然后,我使用CURLOPT_POSTFIELDS值添加参数。我是否缺少PUT请求的查询参数所需的内容?与POST请求不同,PUT请求需要指定要发送到服务器的内容长度。以下是一个例子: // data to be sent $post_dat

我试图使用PHP和curl发送一个PUT请求,但我的查询参数似乎没有发送到API。日志验证请求是否作为PUT传入,但参数没有发出请求。我遵循了在internet上找到的每个示例,这些示例描述了如何构建查询参数手动构建并使用http_build_query函数。然后,我使用CURLOPT_POSTFIELDS值添加参数。我是否缺少PUT请求的查询参数所需的内容?

与POST请求不同,PUT请求需要指定要发送到服务器的内容长度。以下是一个例子:

// data to be sent
$post_data = "...soem data";

// so that you get response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// this is must for doing PUT
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($post_data)));

// Doing PUT
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data ); 
如果在此之后仍然存在问题,请通过启用详细模式运行curl,它将显示curl操作上的debug msg:

curl_setopt($ch, CURLOPT_VERBOSE, true);