Lib Curl, Twitter API & “Expect: 100-continue” PAIN and How To Fix it

*this post will probably not be worthwhile for 99% of the normal readers. But for those having the same issue it will be priceless.*

I have been working on a new twitter app for a couple months and at approximately 5pm on December 23rd 2008 (3 days ago) it all went boom.

All of my php curl (lib curl) requests started returning:

HTTP/1.1 417 Expectation Failed

and the exact html returned is:

<title>417 Expectation Failed</title>
<h1>Expectation Failed</h1>
<p>The expectation given in the Expect request-header
field could not be met by this server.</p>
<p>The client sent<pre>
Expect: 100-continue
but we only allow the 100-continue expectation.</p>

It appears Twitter started being super anal about requests being sent and in particular the http/1.1 RFC post requests.

Anyway it took be a long time searching the web and trying various things until I figured out the solution by looking at some of the lib curl compilation files.

Just add:

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

and you will be fixed!