简体   繁体   中英

curl error 411 when migrating from PHP 5.3 to 5.6

I'm migrating from PHP 5.3 to PHP 5.6.3. When doing a curl request, it now gives me an error:

The requested URL returned error: 411 Length Required

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.

So in short; I have exact the same setup, data, format etc. but now curl gives a 411 error.

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:

cURL support enabled

cURL Information 7.39.0

Age 3

Features

AsynchDNS Yes

CharConv No

Debug No

GSS-Negotiate No

IDN Yes

IPv6 Yes

krb4 No

Largefile Yes

libz Yes

NTLM Yes

NTLMWB No

SPNEGO Yes

SSL Yes

SSPI Yes

TLS-SRP No

Protocols dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp

Host i386-pc-win32

SSL Version OpenSSL/1.0.1i

ZLib Version 1.2.7.3

libSSH Version libssh2/1.4.3

Ok, I had to remove the content-length part since curl does this automatically for non 'put' requests.

The reason why my code worked under PHP 5.3 and not with PHP 5.6.3 is unknown to me. Yet this is the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM