Welcome to MSDN Blogs Sign in | Join | Help

Twitter Dishing Out 417 - Expectation Failed to .Net Clients

My little Twitter app was broke since past few days with error 417 - Expectation Failed. Infect most .Net apps calling Twitter APIs would be broken right now so I thought to write this up.

This error is seemingly because Twitter servers have started rejecting Expect HTTP header with value "!00-Continue". I'm not sure if this was planned event or enough warnings were issued to developers but it would be guaranteed to drive you nuts.

The error is because of default behavior in HttpWebRequest object that adds an HTTP header called Expect with value "100-Continue" to almost every outgoing POST request. This header basically tells the server that it's going to send all the data in form in the next request instead of current request so that if server has redirects or auth then it doesn't have to resend it all over again. This is a good thing if your web form has lots of data or if you are on low latency network or most servers in the word have either redirects or auth when submitting forms but a bad thing for server performance because now it gets hit twice for each request. I think performance might be the reason Twitter has turned off support for such two partter POST requests which unfortunately happens to be the default for HttpWebRequest.

In any case, it turns out that HttpWebRequest does all these thing under the hood so to get rid of this error you will need to set a static flag in ServicePointManager class like this:

System.Net.ServicePointManager.Expect100Continue = false;

Above statement will cause elimination of HTTP Expect header from your calls to Twitter and it will be happy again.

I'm using Yedda's C# wrapper for Twitter APIs for QckTwit so above line goes in to start of ExecutePostCommand method.

PS: If you are new to Twitter try out free simple lightweight app QckTwit. It just sits in your system tray, asks you about what you are doing at reminder interval you set, updates the Twitter and gets out of your way!

Published Saturday, December 27, 2008 1:20 AM by shitals
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Monday, December 29, 2008 4:35 PM by Algorithms for the masses - julian m bucknall

# Twitter notification broken with Graffiti 1.2?

Nope, but, boy, was it a coincidence! I use Scott Watermasysk's Graffiti Plug-in library to add Twitter notifications when I add new posts to this blog. Well, the weekend before last, I upgraded to Graffiti CMS 1.2 and blogged about it. The plug-in duly

Friday, January 02, 2009 3:45 PM by Bret Stateham

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Thanks for the post!  I am using Yedda's wrapper as well, and this fixed my problem.  

Saturday, January 03, 2009 2:08 AM by Rajib Bahar

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Thanks for the solution. You just made my day. I wrote this tool to complement wikipedia. It allows user to save articles for offline viewing as well as sharing it via status message in facebook and twitter. See http://apps.facebook.com/wikiarticlesaver.

Wednesday, January 07, 2009 2:12 PM by Zack Steinkamp

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

For anyone using the CURL library, this will fix the problem...

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

Thursday, January 08, 2009 11:41 AM by mike amundsen

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

hah! just ran into this Tiwtter bug today. thanks for posting the fix.

Wednesday, January 14, 2009 11:18 PM by RockyH

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Thanks. I've been writing my own twitter aps and this was exactly what I was experiencing. Nice work!!!

Friday, January 16, 2009 2:15 PM by Nik

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Thanks Shital, we use Yedda at Retaggr.com - was wondering why we weren't seeing too many tweets!

Monday, February 23, 2009 6:23 AM by Gregor Spowart

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Thanks for this - sorted out my problem!

Thursday, March 12, 2009 2:44 PM by Blake Carlile

# Thanks! Fixed!

Thanks, this fixed it. I'm using Yedda too. Now to figure out what to do with this :)

Tuesday, March 17, 2009 7:45 AM by Murilo

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Thanks A LOT!! It saved my newly born App!

Thursday, March 19, 2009 3:35 AM by tonex

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

I wonder why this doesn't work on mine.  I'm using VS2008 and 3.5 Framework.  I still get the 417 error.

Tuesday, March 24, 2009 2:37 PM by Vlad Loidap

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

I'm using Yedda too. Thanks, this fixed it for me too!

Sunday, March 29, 2009 1:01 PM by regmee

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

It doesn't work anymore. I couldn't get it fixed. I guess, something more is broken now.

Even the tested application QckTwit (http://qcktwit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21094#ReleaseFiles) with the correction doesn't seem to work.

# The HungryCoder » Blog Archive » 417 status and PHP cURL

Sunday, May 31, 2009 6:07 PM by Jeff

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Is anyone else starting to get this error again even with the code:

System.Net.ServicePointManager.Expect100Continue = false;

The 'QckTwit' app is getting this as well.

Thanks.

Saturday, June 06, 2009 10:27 PM by Randy

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Thank you.  I have been banging my head against the wall with this one.

Friday, June 26, 2009 1:53 PM by Sam

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Yes this still happens even with Expect100Continue = false.

Puzzling, as it used to work. The only solution is to only use GET requests, as no Expect header is sent at all (as only one connection, no post to resend).

I use HTTPS for all my oAuth requests, even on twitter, this is why I prefer post, as only the form is encrypted, when using querystrings  (GET requests), no encryption takes place, even on HTTPS.

So the transfer of oAuth token via GETS is insecure, but this is the only acceptable way to Twitter!

Wednesday, July 29, 2009 5:11 PM by whaites

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

I was having intermittent issues with the 417 error using the Yedda .net wrapper even after adding the Expect100continue = false. Then I noticed some slight differences in some of the examples on the web with this issue.

I modified the Yedda code to use  HttpWebRequest, not WebRequest -

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

AND I set the Expect100continue = false like this:

request.ServicePoint.Expect100Continue = false;

Finally, I also changed the WebResponse to:

HttpWebResponse response = (HttpWebResponse)request.GetResponse()

Since these changes, I haven't had the 417 error. Hopefully setting Expect100continue via the HttpWebRequest class has this sorted...

Wednesday, August 05, 2009 10:17 PM by Joe

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

Whaites,

Thanks for the tip about using HttpWebRequest. Everything works great on my post attempt now.

I have been using Tweetsharp and the post was working but not proxy and basic auth which I need to do behind my (cisco based) proxy server. I can see both my proxy authorization and authorization headers before I read the response object as well. I will figure out how to put that into tweetsharp.

What is your opinion about the relative merits of the twitter API: .net vs java, tweet# vs yedda.

Thanks

Joe

Tuesday, September 01, 2009 4:55 AM by sandip patel - Milestone internet marketing

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

great post. it worked for me too. i appreciate you code thanks.

Tuesday, September 01, 2009 4:56 AM by sandip patel - Milestone internet marketing

# re: Twitter Dishing Out 417 - Expectation Failed to .Net Clients

great post. it worked for me too. i appreciate you code thanks. Sandip

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker