PHP curl报错"Problem (2) in the Chunked-Encoded data"解决方案
PHP curl报错"Problem (2) in the Chunked-Encoded data"解决方案
Windows环境下遇到一个很奇怪的问题,使用PHP curl发送请求报错:错误信息:Problem (2) in the Chunked-Encoded data
但是使用浏览器直接访问又正常,怀疑是php_curl.dll扩展本身的bug,解决方案如下:
在PHP curl头部添加HTTP版本信息即可解决:
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
即可修复该问题。
//curl模拟post请求向指定url发送json等
function curlPost($url,$data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
$errorno=curl_errno($ch);
// echo curl_error($ch);
return $tmpInfo;
}
版权声明:若无特殊注明,本文皆为《菜鸟站长》原创,转载请保留文章出处。
本文链接:PHP curl报错"Problem (2) in the Chunked-Encoded data"解决方案 - https://wlphp.com/?post=119