Using $headers_new[] = 'Expect:';
does work unless the $headers_new
array contains a string that is 'Expect: 100-continue'
. In this case you need to remove it from the array otherwise it will be expecting the 100 continue (logically).
Because in your code you use getallheaders()
and you're not checking if it contains an Expect: 100-continue
header already so this probably is the case in your case.
Here is a summary for the general situation (and the script that created it):
PHP Curl HTTP/1.1 100 Continue and CURLOPT_HTTPHEADER
GET request ..........................................: Continue: No
GET request with empty header ........................: Continue: No
POST request with empty header .......................: Continue: Yes
POST request with expect continue explicitly set .....: Continue: Yes
POST request with expect (set to nothing) as well ....: Continue: Yes
POST request with expect continue from earlier removed: Continue: No
Code:
<?php
$ch = curl_init('http://www.iana.org/domains/example/');
function curl_exec_continue($ch) {
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$continue = 0 === strpos($result, "HTTP/1.1 100 Continuex0dx0ax0dx0a");
echo "Continue: ", $continue ? 'Yes' : 'No', "
";
return $result;
}
echo "GET request ..........................................: ", !curl_exec_continue($ch);
$header = array();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
echo "GET request with empty header ........................: ", !curl_exec_continue($ch);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('hello'));
echo "POST request with empty header .......................: ", !curl_exec_continue($ch);
$header[] = 'Expect: 100-continue';
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
echo "POST request with expect continue explicitly set .....: ", !curl_exec_continue($ch);
$header[] = 'Expect:';
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
echo "POST request with expect (set to nothing) as well ....: ", !curl_exec_continue($ch);
unset($header[0]);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
echo "POST request with expect continue from earlier removed: ", !curl_exec_continue($ch);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…