I’ve been getting 417 response codes (Expectation failed) while making requests with PHP/curl to tinyurl.com (I’ll probably publish that project here in a week or two). Well, its very annoying. took me some time to figure that one out.
If someone else wonders about it, that’s the deal:
If the content length (of the request post data) is bigger than 1KB (>=1025 bytes), the client (curl in our case) sends the request with a “Expect: 100-continue” header and without the actual post data, than awaits for a response with status 100, and than finally sends the actual post data.
The problem is that many servers (lighttpd 1.4 among them, fixed at 1.5) doesn’t support that, which is exactly why I got the 417 error when my client attempted to use that header.
To make curl suppress that header, and just send the request/post data normally while ignoring the fact that the post data is more than 1KB, add the following piece of code:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
Adding a header with no value makes it overwrite the original value and suppress the header, which should make everything work fine.
It should be noted that every time you set CURLOPT_HTTPHEADER it overwrites the original HTTPHEADER value and not appends to it, so if you already set it, you should simply add ‘Expect:’ to your existing HTTPHEADER array instead of adding the entire line.