How can I stop cURL from using 100 Continue? How can I stop cURL from using 100 Continue? curl curl

How can I stop cURL from using 100 Continue?


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_HTTPHEADERGET request ..........................................: Continue: NoGET request with empty header ........................: Continue: NoPOST request with empty header .......................: Continue: YesPOST request with expect continue explicitly set .....: Continue: YesPOST request with expect (set to nothing) as well ....: Continue: YesPOST 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 Continue\x0d\x0a\x0d\x0a");    echo "Continue: ", $continue ? 'Yes' : 'No', "\n";    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);


Thanks for the script, Hakre. Since I needed this for HTTP PUT, I extended it a bit with the following results:

GET request ..........................................: Continue: NoGET request with empty header ........................: Continue: NoPOST request with empty header .......................: Continue: YesPOST request with expect continue explicitly set .....: Continue: YesPOST request with expect (set to nothing) as well ....: Continue: YesPOST request with expect continue from earlier removed: Continue: NoPUT request with empty header ........................: Continue: YesPUT request with expect continue explicitly set ......: Continue: YesPUT request with expect (set to nothing) as well .....: Continue: YesPUT request with expect continue from earlier removed : Continue: NoDELETE request with empty header .....................: Continue: YesDELETE request with expect continue explicitly set ...: Continue: YesDELETE request with expect (set to nothing) as well ..: Continue: YesDELETE request with expect continue from earlier removed : Continue: No

Here's the script:

<?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 Continue\x0d\x0a\x0d\x0a");    echo "Continue: ", $continue ? 'Yes' : 'No', "\n";    return $result;}// --- GETecho "GET request ..........................................: ", !curl_exec_continue($ch);$header = array();curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "GET request with empty header ........................: ", !curl_exec_continue($ch);// --- POSTcurl_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);// --- PUTcurl_setopt($ch, CURLOPT_PUT, TRUE);$header = array();curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "PUT request with empty header ........................: ", !curl_exec_continue($ch);$header[] = 'Expect: 100-continue';curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "PUT request with expect continue explicitly set ......: ", !curl_exec_continue($ch);$header[] = 'Expect:';curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "PUT request with expect (set to nothing) as well .....: ", !curl_exec_continue($ch);unset($header[0]);curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "PUT request with expect continue from earlier removed : ", !curl_exec_continue($ch);// --- DELETEcurl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");$header = array();curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "DELETE request with empty header .....................: ", !curl_exec_continue($ch);$header[] = 'Expect: 100-continue';curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "DELETE request with expect continue explicitly set ...: ", !curl_exec_continue($ch);$header[] = 'Expect:';curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "DELETE request with expect (set to nothing) as well ..: ", !curl_exec_continue($ch);unset($header[0]);curl_setopt($ch, CURLOPT_HTTPHEADER, $header);echo "DELETE request with expect continue from earlier removed : ", !curl_exec_continue($ch);?>


For removing the header 101 continue use this

curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:"));