[英]curl error 411 when migrating from PHP 5.3 to 5.6
I'm migrating from PHP 5.3 to PHP 5.6.3. 我正在从PHP 5.3迁移到PHP 5.6.3。 When doing a curl request, it now gives me an error:
现在执行curl请求时,它给我一个错误:
The requested URL returned error: 411 Length Required
请求的URL返回错误:411所需长度
All the data is the same. 所有数据都相同。 A vardump on the msg returns a string of 620. The length is correct, nothing of the variables are changed and contain the same data whether it is PHP 5.3 or PHP 5.6.3.
味精上的vardump返回字符串620。长度正确,任何变量均未更改,并且包含相同数据,无论是PHP 5.3还是PHP 5.6.3。
So in short; 简而言之 I have exact the same setup, data, format etc. but now curl gives a 411 error.
我具有完全相同的设置,数据,格式等,但是现在curl出现411错误。
This is a snippet of my code: 这是我的代码的片段:
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $this->_url);
curl_setopt($handle, CURLOPT_FAILONERROR, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: ".$request."","Content-length: ".strlen($msg)));
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $msg);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($handle, CURLOPT_USERPWD, $this->_httpUser.':'.$this->_httpPassword);
$response = curl_exec($handle);
PHPINFO curl: PHPINFO curl:
cURL support enabled
启用了cURL支持
cURL Information 7.39.0
cURL信息7.39.0
Age 3
3岁
Features
特征
AsynchDNS Yes
AsynchDNS是
CharConv No
CharConv否
Debug No
调试号
GSS-Negotiate No
GSS协商号
IDN Yes
IDN是
IPv6 Yes
IPv6是
krb4 No
krb4否
Largefile Yes
大文件是
libz Yes
libz是
NTLM Yes
NTLM是
NTLMWB No
NTLMWB否
SPNEGO Yes
SPNEGO是
SSL Yes
SSL是
SSPI Yes
SSPI是
TLS-SRP No
TLS-SRP否
Protocols dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
协议dict,文件,ftp,ftp,gopher,http,https,imap,imaps,ldap,pop3,pop3s,rtsp,scp,sftp,smtp,smtps,telnet,tftp
Host i386-pc-win32
主机i386-pc-win32
SSL Version OpenSSL/1.0.1i
SSL版本OpenSSL / 1.0.1i
ZLib Version 1.2.7.3
ZLib版本1.2.7.3
libSSH Version libssh2/1.4.3
libSSH版本libssh2 / 1.4.3
Ok, I had to remove the content-length part since curl does this automatically for non 'put' requests. 好的,我必须删除内容长度部分,因为curl会针对非“放置”请求自动执行此操作。
The reason why my code worked under PHP 5.3 and not with PHP 5.6.3 is unknown to me. 我不知道为什么我的代码在PHP 5.3下而不在PHP 5.6.3下工作的原因。 Yet this is the solution.
但这是解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.