PHP curl_exec returns both HTTP/1.1 100 Continue and HTTP/1.1 200 OK separated by space
I will opt for #1.You can force curl to send empty "Expect" header, by adding:
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:"));
to your code
If you want check it manually, you should define your own header callback and maybe write callback (look for CURLOPT_HEADERFUNCTION and CURLOPT_WRITEFUNCTION in curl_setopt doc), which has simply to ignore all "HTTP/1.1 100 Continue" headers.
Here's another method that uses the approach I described in the comment by parsing the response into header vs. body using CURLINFO_HEADER_SIZE
:
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://test/curl_test.php");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLINFO_HEADER_OUT, 1);curl_setopt($ch, CURLOPT_HEADER, 1);// sets multipart/form-data content-typecurl_setopt($ch, CURLOPT_POSTFIELDS, array( 'field1' => 'foo', 'field2' => 'bar'));$data = curl_exec($ch);// if you want the headers sent by CURL$sentHeaders = curl_getinfo($ch, CURLINFO_HEADER_OUT);$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);curl_close($ch);$header = substr($data, 0, $headerSize);$body = substr($data, $headerSize);echo "==Sent Headers==\n$sentHeaders\n==End Sent Headers==\n";echo "==Response Headers==\n$headers\n==End Response Headers==\n";echo "==Response Body==\n$body\n==End Body==";
I've tested this, and it results in the following output:
==Sent Headers==POST /curl_test.php HTTP/1.1Host: testAccept: */*Content-Length: 242Expect: 100-continueContent-Type: multipart/form-data; boundary=----------------------------d86ac263ce1b==End Sent Headers====Response Headers==HTTP/1.1 100 ContinueHTTP/1.1 200 OKDate: Fri, 06 Jul 2012 14:21:53 GMTServer: Apache/2.4.2 (Win32) PHP/5.4.4X-Powered-By: PHP/5.4.4Content-Length: 112Content-Type: text/plain==End Response Headers====Response Body==**FORM DATA**array(2) { ["field1"]=> string(3) "foo" ["field2"]=> string(3) "bar"}**END FORM DATA**==End Body==
I have come across this with 100s and 302s etc it's annoying but sometimes needed (gdata calls etc) so i would say leave curl returning all headers and extract the body a little differently.
I handle it like this (can't find my actual code but you'll get the idea):
$response = curl_exec($ch);$headers = array();$body = array();foreach(explode("\n\n", $response) as $frag){ if(preg_match('/^HTTP\/[0-9\.]+ [0-9]+/', $frag)){ $headers[] = $frag; }else{ $body[] = $frag; }}echo implode("\n\n", $headers);echo implode("\n\n", $body);
I begrudge the longwinded hackish method (would prefer it if curl marked the body content somehow) but it has worked well over the years. let us know how you get on.