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

Posted by

*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!

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

  1. Brennan

    I know many people who will be able to use this. I haven’t really gotten into the whole Twitter thing yet but it seems like every blogger is saying how great it is so I might just have to join in on it.

  2. Internet Marketing Industry

    I have to agree with the above – definitely interested in learning about this new app – glad to see you found the solution – maybe the issue happened because of all of the apps being built for twitter now a days -looking forward to what you have to share.

  3. Mark

    Long time reader, first time poster. I know enough about Twitter to be dangerous and I got myself banned tonight by signing up with a service called Twauter that creates auto follows. Anyway I do have a twitter app that is pretty cool called ObamaTweet at . It pulls all Tweets with the word Obama from the Twitter DB and displays a realtime Obama River. I’m getting it ready for a big marketing push before the swearing in. Any tips would be appreciated.

  4. Pingback: Posts about Internet Marketing as of December 30, 2008 | The Lessnau Lounge

  5. Joe Tech

    Nice error. I just use the API rather than curl, but that has its limitations. I assume you’re making requests that don’t require the user’s twitter account to be authenticated.

  6. BusinessX

    I am having to advance my programming skills to do some of the things I want to do (including API). So, I imagine I will be returning to this post someday soon.

  7. Dick

    I lloked through the stuff again and sopped at the place where there is a photo of your elder daughter. The girl is so cute.She will be a doctor for sure.

  8. Mr. School Fundraising ideas

    I guess I am not a uber geek because I have no clue what is up with that twitter. The expectation failed but it says that the 100-expect is allowed. What does that mean, crazy stuff, and we wonder if machines will ever take over the human race… sorry to be the let down, they have already.

    Mr. School Fundraising Ideas

  9. Pingback: Twitter-API - Probleme Tweets auszulesen und wie mans es fixt | trilodge computin blog

  10. Mike Peters

    Count me in that 1% :-)

    We just had a similar issue with php-cgi and Nginx that took a few hours to trace. Turns out php-cgi adds 2 seconds when your POSTed data contains more than 1,000 characters and missing the Expect header.

  11. Derek P. Collins

    Ah, thank you so much for this! I wasn’t having this issue on my local server, but when I moved my Twitter app onto the production server I got this error. Your solution fixed it right up! Thank you, thank you, thank you!

  12. JumpByte

    Anybody wanna help me out? I’m using VB.NET and System.Net.ServicePointManager.Expect100Continue = False doesn’t solve my problem :\


  13. Pingback: pecl_http で POST を送信する際の注意点 - セサミン・ラボ

  14. Electric Guitars

    Thanks for this snippet. I just started getting this error message on a new WP plugin that I am writing, and a quick Google search led mw to your website.

    Yes it does seem that Twitter has gone a bit “anal” about things, but I guess we have to follow their rules.

    Many thanks


Comments are closed.