68

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

Posted December 29th, 2008 by Jeremy Schoemaker

*this post will probably not be worthwhile for 99% of the normal shoemoney.com 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:

<html><head>
<title>417 Expectation Failed</title>
</head><body>
<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
</pre>
but we only allow the 100-continue expectation.</p>
</body></html>

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:

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

and you will be fixed!

Disclaimer

Before acting on this post, be sure to read my Disclaimer.

- Comment Likes - Comment Dislikes

68 comments. What say you?

  1. Good Comment?
    Zx.MYS

    Thank you for saving my time!!

  2. Good Comment?
    mariochampion

    god bless the internet! (and you, and all the ships at sea ; )

  3. Good Comment?
    Hannes

    I was using godaddy and wanted to send messages to twitter. It just failed.

    Thanks to you I got it to work. Thanks, mate!

  4. Good Comment?
    Billy Ellison

    Thank you so much! This was really frustrating me

  5. Good Comment?
    Naval

    Thanks a lot it really help me most i was facing same problem.

  6. Good Comment?
    Symphony

    But for those having the same issue it will be priceless.

    Absolutly! It’s really helpful! Thanks a lot!

  7. Good Comment?
    Jeans

    Thank you very much.It work!

  8. Good Comment?
    matthew

    THANK YOU!!!! Struggled with this for hours until I found your post and then like magic it was fixed. THANK YOU!

  9. Good Comment?
    dnuske

    god bless you

    and all the people like you around the world

    =)

  10. Good Comment?
    blackwinged

    yayy, you saved my day!
    wouldn´t have figured this out so quickly on my own.

  11. Good Comment?
    danish

    thanks man … it really worked :)

  12. Good Comment?
    Al Becs

    Oh, you should have done great research. Your solution works perfectly!

    thanks!

  13. Good Comment?
    mystral-kk

    Thanks! Your solution works fine.

  14. Good Comment?
    alex

    YES! Thanks!

  15. Good Comment?
    Rodney Joyce

    There’s some hint as to where to add this line but I am not 100% sure:
    http://devblog.yedda.com/index.php/2007/05/16/twitter-c-library/#comments

  16. Good Comment?
    JumpByte

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

    thanks!

  17. Good Comment?
    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!

  18. Good Comment?
    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.

  19. Good Comment?
    Drew

    Thanks for the tip. This is exactly what I needed to make this work at:
    http://twitter.com/CelleCast

  20. Good Comment?
    Personal Development Tips

    This is great stuff! I was having this problem exactly! When I searched for 100-continue expectation this is what I found. I added that line and then voila! It worked!

    Great job and thanks a bunch!

  21. Good Comment?
    Mr. School Fundraising Ideas

    I have heard of Twitter but haven’t quite gotten the whole concept why and how it is a big deal and how it can help you in your business?

  22. Good Comment?
    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.

    Thanks
    Mr. School Fundraising Ideas

  23. Good Comment?
    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.

  24. Good Comment?
    Dick

    I am thinking of the stuff again ready to make some progress in my self-improvement.

  25. Good Comment?
    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.

  26. Good Comment?
    Dick

    Let’s call a spade a spade.

  27. Good Comment?
    Karl hadwen

    Thanks for the code love nerdy stuff like this lol

  28. Good Comment?
    Karl hadwen

    Thanks for this love nerdy code :)

  29. Good Comment?
    iskandarX

    This is what we call “AMAZING”. Dude you are awsome working for this.

  30. Good Comment?
    memory

    ummmm, i guess i’m part of the 99%…..it’s all greek to me!

  31. Good Comment?
    Typhoon

    By the way what’s the new application all about..Is it coming soon in the new year?

  32. Good Comment?
    Typhoon

    Sorry but shoe didn’t update his blog with this news..
    Google Have Updated PageRank of every blog almost..
    My blog is a PR3 from PR0

  33. Good Comment?
    Typhoon

    Waiting for your new tool..but no idea what you wrote in this post :{}

  34. Good Comment?
    Dick

    I ‘ve got interested in the information laying-out. ’tis good to know it.

  35. Good Comment?
    Juuso

    Nice… but where’s the super affiliate post? :)

  36. Good Comment?
    RockaFeller

    Wow, earning so much money and… YOU STILL CODE?!

  37. Good Comment?
    Kyle Irwin

    Welcome to curl101. Retards.

  38. Good Comment?
    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.

  39. Good Comment?
    Owen

    That come just in time. Working on a Twitter thingy at the moment!

  40. Good Comment?
    Learn English Online

    Thanks a million for the knowledge.

  41. Good Comment?
    Hyder

    Thanks for this info my developer might need to know this, it’s all Greek to me, for a twitter widget we’re building.

  42. Good Comment?
    Work At Home

    Wow.. I would have give up doing this work by now. Well done

  43. Good Comment?
    Blog And Make Cash

    Nice trick, I was looking for it since days! curl rocks, definitely.

  44. Good Comment?
    Wesley

    I’ve used the twitter api with curl as well and never had to do this, this is definitely weird.

  45. Good Comment?
    Affiliate Showdown

    Im now starting to wonder what you got cooking over there.

  46. Good Comment?
    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 http://www.obamatweet.com/ . 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.
    ~Mark
    mark@adsenserockstar.com

  47. Good Comment?
    Taris Janitens

    Thanks for the heads up!! I’m sure someone will be able to use this, ableit not me :)

  48. Good Comment?
    Day

    That’s so you can’t say Expect-100: gimme(document.cookie)

  49. Good Comment?
    Jason

    Thanks for the heads-up! Just getting my feet wet now with the Twitter API…

  50. Good Comment?
    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.

  51. Good Comment?
    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.

    • Good Comment?
      Taris Janitens

      You and me both – I just don’t wanna be tied to my phone 24-7 personally which is why I am avoiding it

      • Good Comment?
        SEO Tips South Africa

        I’ve also been avoiding twitter, but it seems that the mainstream pressure is going to force me to re-appraise and try to get into it!

  52. Good Comment?
    Internet Marketing Access

    I think I am now more interested in the twitter app that you have been working on for the past few months. lol What does it do or is that a secret?

  53. Good Comment?
    Steven-Sanders

    Good to know. Thanks for the great info!

  54. Good Comment?
    jtGraphic

    Seriously… I love when you post nerdy stuff :) This stuff is sooo useful. Thanks.

    • Good Comment?
      meethere

      can’t wait to see your twitter tool/site… :D

      • Good Comment?
        jtGraphic

        Thanks. I’ll keep people posted!

  55. Good Comment?
    Wesley

    It just means that curl should send an empty “Expect:” header over to twitter, since otherwise twitter may misinterpret.

  56. Good Comment?
    Abel Perez

    Awesome, thanks for sharing such a nice time saver :)

Join the Discussion

*Discount rate good on new registrations only. Credits or refunds cannot be issued on previous registrations. Discount rate good through February 6, 2010, prevailing rate applies after that.