PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; padding:0px; margin:0px; word-break:normal; border:0px; display:inline; line-height:inherit; word-wrap:normal; background:transparent">作者:zhanhailiang 日期:2015-01-23</code>
本地环境:
<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; padding:0px; margin:0px; word-break:normal; border:0px; display:inline; line-height:inherit; word-wrap:normal; background:transparent">系统版本:Microsoft Windows 6.1.7601PHP版本:PHP 5.3.29php_curl.dll扩展版本:7.35.0</code>
Windows环境下遇到一个很奇怪的问题,使用PHP curl发送请求报错:
<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; padding:0px; margin:0px; word-break:normal; border:0px; display:inline; line-height:inherit; word-wrap:normal; background:transparent">错误码:56错误信息:Problem (2) in the Chunked-Encoded data</code>
但是使用浏览器直接访问又正常,怀疑是php_curl.dll扩展本身的bug,解决方案如下:
在PHP curl头部添加HTTP版本信息即可解决:
<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; padding:0px; margin:0px; word-break:normal; border:0px; display:inline; line-height:inherit; word-wrap:normal; background:transparent">curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);</code>
即可修复该问题。