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

by Jeremy Schoemaker on December 29, 2008 · 76 comments

*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]curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Expect:’));[/php]

and you will be fixed!

About the author...

– who has written 2415 posts on ShoeMoney.com.

Hi I am Jeremy Schoemaker and ShoeMoney.com is my blog. 99% of the post here are done by me but you will see others occasionally make guest posts. This blog is fun to write but for my day job I run several online companies.

Images provided by ShutterStock


Mark recommends you read these posts also:

  1. cash How To Make $100 A Day With An Info Product (Part 4)
  2. sportwizards How A $1295 Gambling Debt Turned Me Into An Online Marketer
  3. 300px-Boschsevendeadlysins Seven Deadly Sins For People Trying to Make Money Online

{ 73 comments… read them below or add one }

1 jtGraphic December 29, 2008 at 9:40 pm

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

Reply

2 meethere December 30, 2008 at 4:14 pm

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

Reply

3 jtGraphic December 30, 2008 at 7:00 pm

Thanks. I’ll keep people posted!

Reply

4 Steven-Sanders December 29, 2008 at 9:43 pm

Good to know. Thanks for the great info!

Reply

5 The Poker Jerk December 29, 2008 at 11:34 pm

I’m just as interested in this as the post above ^^^^^

Reply

6 Taris Janitens December 30, 2008 at 12:28 am

LOL oh poker jerk – you as such a jerk hehehe

Reply

7 SEO Tips South Africa January 2, 2009 at 4:12 am

Heheheheh….that will be MISTER JERK to you…..

Reply

8 Internet Marketing Access December 29, 2008 at 9:58 pm

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?

Reply

9 jtGraphic December 30, 2008 at 1:55 am

Ditto…

Reply

10 Brennan December 29, 2008 at 10:32 pm

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.

Reply

11 Taris Janitens December 30, 2008 at 8:53 am

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

Reply

12 SEO Tips South Africa January 2, 2009 at 4:15 am

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!

Reply

13 Internet Marketing Industry December 29, 2008 at 11:43 pm

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.

Reply

14 Jason December 30, 2008 at 12:14 am

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

Reply

15 Day December 30, 2008 at 12:26 am

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

Reply

16 Taris Janitens December 30, 2008 at 12:27 am

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

Reply

17 Mark December 30, 2008 at 12:46 am

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

Reply

18 Affiliate Showdown December 30, 2008 at 1:33 am

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

Reply

19 Wesley December 30, 2008 at 2:03 am

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

Reply

20 Blog And Make Cash December 30, 2008 at 2:23 am

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

Reply

21 Work At Home December 30, 2008 at 3:20 am

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

Reply

22 Hyder December 30, 2008 at 4:27 am

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

Reply

23 Learn English Online December 30, 2008 at 5:25 am

Thanks a million for the knowledge.

Reply

24 Owen December 30, 2008 at 6:17 am

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

Reply

25 Joe Tech December 30, 2008 at 11:26 am

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.

Reply

26 Kyle Irwin December 30, 2008 at 12:48 pm

Welcome to curl101. Retards.

Reply

27 RockaFeller December 30, 2008 at 4:30 pm

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

Reply

28 Juuso December 31, 2008 at 1:03 am

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

Reply

29 Dick December 31, 2008 at 3:34 am

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

Reply

30 Typhoon December 31, 2008 at 3:42 am

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

Reply

31 Typhoon December 31, 2008 at 3:45 am

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

Reply

32 Typhoon December 31, 2008 at 3:55 am

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

Reply

33 memory December 31, 2008 at 8:35 am

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

Reply

34 iskandarX December 31, 2008 at 9:12 am

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

Reply

35 Karl hadwen December 31, 2008 at 9:13 am

Thanks for this love nerdy code :)

Reply

36 Karl hadwen December 31, 2008 at 9:14 am

Thanks for the code love nerdy stuff like this lol

Reply

37 Dick December 31, 2008 at 9:21 am

Let’s call a spade a spade.

Reply

38 SEO Tips South Africa January 2, 2009 at 4:21 am

Heheheheheh! And a nerd a nerd, or nerdy stuff, nerdy stuff!

Reply

39 BusinessX January 1, 2009 at 2:55 pm

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.

Reply

40 Dick January 2, 2009 at 11:40 pm

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

Reply

41 Dick January 3, 2009 at 9:44 pm

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.

Reply

42 Mr. School Fundraising ideas January 5, 2009 at 3:56 pm

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

Reply

43 Mr. School Fundraising Ideas January 9, 2009 at 10:30 am

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?

Reply

44 Personal Development Tips January 13, 2009 at 10:05 pm

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!

Reply

45 Drew January 18, 2009 at 2:53 am

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

Reply

46 Mike Peters January 21, 2009 at 7:27 pm

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.

Reply

47 Derek P. Collins January 23, 2009 at 12:20 pm

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!

Reply

48 JumpByte January 26, 2009 at 1:00 am

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

thanks!

Reply

49 Rodney Joyce January 27, 2009 at 9:30 pm

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

Reply

50 alex February 13, 2009 at 12:27 am

YES! Thanks!

Reply

51 mystral-kk April 8, 2009 at 1:57 am

Thanks! Your solution works fine.

Reply

52 Al Becs May 14, 2009 at 2:10 am

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

thanks!

Reply

53 danish June 1, 2009 at 2:44 am

thanks man … it really worked :)

Reply

54 blackwinged June 3, 2009 at 5:38 am

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

Reply

55 dnuske June 7, 2009 at 2:44 am

god bless you

and all the people like you around the world

=)

Reply

56 matthew August 29, 2009 at 11:32 pm

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

Reply

57 Jeans October 21, 2009 at 11:58 pm

Thank you very much.It work!

Reply

58 Symphony November 11, 2009 at 9:16 am

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

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

Reply

59 Naval November 28, 2009 at 1:06 am

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

Reply

60 Billy Ellison December 16, 2009 at 11:01 pm

Thank you so much! This was really frustrating me

Reply

61 Hannes February 10, 2010 at 6:45 am

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

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

Reply

62 mariochampion February 18, 2010 at 7:42 pm

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

Reply

63 Zx.MYS February 21, 2010 at 10:03 am

Thank you for saving my time!!

Reply

64 Electric Guitars March 24, 2010 at 12:02 am

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

ness

Reply

65 Kenton Monasterio April 25, 2010 at 5:09 am

What a planet we live in!!?! It just exhibits us all as much as the fools we are…

Reply

66 Rosenda Lenoch April 25, 2010 at 6:34 am

Useful submit. Thanks for talk about

Reply

67 shiju April 28, 2010 at 2:22 am

thnx a lot for this fix.. buddy

Reply

68 Sankha August 5, 2010 at 2:56 am

Thanks man! You gained good Karma (Kamma).
If you want to know a detailed explanation of Kamma then mail to swk_swk@yahoo.com.

Reply

69 Ravi August 14, 2010 at 5:07 pm

Nice time saver

Reply

70 Apply for loans for bad credit today November 27, 2010 at 4:19 am

Well, Thanks for sharing your thoughts. After reading your post I think that twitter is really one of the finest site frm where one can get lots of advantage.

Reply

71 ear hearing loss February 13, 2011 at 11:39 am

Definitely, what a fantastic website and instructive posts, I surely will bookmark your website.Have an awsome day!

Reply

72 Wesley December 31, 2008 at 2:54 am

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

Reply

73 Abel Perez August 19, 2009 at 2:26 am

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

Reply

Leave a Comment

Previous post:

Next post: