Expect Header Issue for .NET developers

568 views
Skip to first unread message

JakeS

unread,
Dec 23, 2008, 11:31:27 PM12/23/08
to Twitter Development Talk
Looks like twitter is updating something and their servers are
returning error 417 for a lot of requests. I looked into it and found
that .NET automatically includes an Expect header containing "100-
continue" on every request unless you specifically tell it not to.

So for any .NET devs having trouble, you can set
System.Net.ServicePointManager.Expect100Continue = false before making
your request to get past this issue.

Alex Payne

unread,
Dec 23, 2008, 11:35:06 PM12/23/08
to twitter-deve...@googlegroups.com
Thanks for helping out with this tip, Jake.

--
Alex Payne - API Lead, Twitter, Inc.
http://twitter.com/al3x

rhysmeister

unread,
Dec 24, 2008, 11:03:36 AM12/24/08
to Twitter Development Talk
Thanks for the tip.

Is this a permanent change?

I'm days away from releasing an app so I will need to do a new build
if this is the case.

Rhys

Carlos

unread,
Dec 24, 2008, 11:24:56 AM12/24/08
to Twitter Development Talk
Thanks Jake, I was getting the same errors.

Is this expected behavior now for Twitter or is this a bug in the new
Twitter release (Not supporting the Expect: Continue header). I'm
writing a multi-service Windows Mobile application and I'd prefer not
changing global http connection settings if I don't have to.

> Thanks for helping out with this tip, Jake.
>

Cameron Kaiser

unread,
Dec 24, 2008, 11:35:19 AM12/24/08
to twitter-deve...@googlegroups.com
> Is this expected behavior now for Twitter or is this a bug in the new
> Twitter release (Not supporting the Expect: Continue header). I'm
> writing a multi-service Windows Mobile application and I'd prefer not
> changing global http connection settings if I don't have to.

Strictly speaking, according to the HTTP spec, it was a bug to *accept*
Expect 100-continue and *not* return a 417 if you weren't prepared to handle
it. See RFC 2616, 14.20. Thus, Twitter's Apache was buggy *before*, but not
now.

There are arguments for shooting first and asking questions later (i.e.,
send Expect: headers all the time even if the remote server doesn't handle
it right), but clients that shoot first should be prepared to retry the
request without Expect: because there are still many servers that don't
know what to do with it. There are also ambiguous situations with servers
that don't understand the header at all and just ignore it; see Section
8.2.3.

--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com
-- Ninety-nine percent of lawyers give the rest a bad name. -------------------

Tom Morris

unread,
Dec 24, 2008, 2:57:49 PM12/24/08
to Twitter Development Talk
On Dec 24, 4:31 am, JakeS <jakesteven...@gmail.com> wrote:
A lot of libraries follow this behaviour. A Twitter app I wrote in PHP
a while back has been logging 417s most of today. I logged in and
added:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

Other libcurl-based libraries may be affected. There are plenty of
reports about 417 and Expect on the cURL website - http://curl.haxx.se/
- and on the websites of particular language bindings.

--
Tom Morris (@tommorris)
<http://tommorris.org>

dean.j.robinson

unread,
Dec 24, 2008, 6:50:12 PM12/24/08
to Twitter Development Talk
Started getting reports from users yesterday that they couldn't login
to hahlo.com.

Turns out that the check I run against "verify credentials" was also
returning code 417 instead of the usual/expected 200, so even though
the check was working to hahlo is looked like it was failing, changed
my check to include code 417 and now its working again.

Strangely though, a local dev copy of Hahlo 4, which also checks
"verify credentials" and also only expects a 200 response, is still
working fine..,




On Dec 25, 6:57 am, Tom Morris <t...@tommorris.org> wrote:
> On Dec 24, 4:31 am, JakeS <jakesteven...@gmail.com> wrote:
>
> > Looks like twitter is updating something and their servers are
> > returning error 417 for a lot of requests.  I looked into it and found
> > that .NET automatically includes an Expect header containing "100-
> > continue" on every request unless you specifically tell it not to.
>
> > So for any .NET devs having trouble, you can set
> > System.Net.ServicePointManager.Expect100Continue = false before making
> > your request to get past this issue.
>
> A lot of libraries follow this behaviour. A Twitter app I wrote in PHP
> a while back has been logging 417s most of today. I logged in and
> added:
> curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
>
> Other libcurl-based libraries may be affected. There are plenty of
> reports about 417 and Expect on the cURL website -http://curl.haxx.se/

Barry Carlyon

unread,
Dec 24, 2008, 7:13:31 PM12/24/08
to twitter-deve...@googlegroups.com
I'm currently getting 417 as well on my php from script using curl

Sent from my iPhone

On 24 Dec 2008, at 23:50, "dean.j.robinson"

PockeTwitDev

unread,
Dec 24, 2008, 4:31:27 PM12/24/08
to Twitter Development Talk
After investigating further it appears this only occurs for .NET
applications which post using form data instead of using URL
parameters. Here's a sample:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = new NetworkCredential(AccountInfo.UserName,
AccountInfo.Password);
request.PreAuthenticate = true;
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String
(Encoding.ASCII.GetBytes(AccountInfo.UserName + ":" +
AccountInfo.Password)));
byte[] bytes = Encoding.UTF8.GetBytes(data); //Data is what's being
posted
request.ContentLength = bytes.Length;
System.Net.ServicePointManager.Expect100Continue = false; //NEED
THIS NOW TO FIX ERROR 417
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Flush();
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse
())
{
using (StreamReader reader = new StreamReader
(response.GetResponseStream()))
{
return reader.ReadToEnd();
}
}

I don't doubt that it's a bug in the development platforms, but even
so it's a pretty common one. It doesn't appear to happen to those
apps which just URLEncode the data and include it in the URL, but I
don't think that's exactly proper specification either :)


On Dec 24, 1:57 pm, Tom Morris <t...@tommorris.org> wrote:
> On Dec 24, 4:31 am, JakeS <jakesteven...@gmail.com> wrote:
>
> > Looks like twitter is updating something and their servers are
> > returning error 417 for a lot of requests.  I looked into it and found
> > that .NET automatically includes an Expect header containing "100-
> > continue" on every request unless you specifically tell it not to.
>
> > So for any .NET devs having trouble, you can set
> > System.Net.ServicePointManager.Expect100Continue = false before making
> > your request to get past this issue.
>
> A lot of libraries follow this behaviour. A Twitter app I wrote in PHP
> a while back has been logging 417s most of today. I logged in and
> added:
> curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
>
> Other libcurl-based libraries may be affected. There are plenty of
> reports about 417 and Expect on the cURL website -http://curl.haxx.se/

weiran

unread,
Dec 25, 2008, 5:21:14 PM12/25/08
to Twitter Development Talk
Setting

> System.Net.ServicePointManager.Expect100Continue = false;

Doesn't work for me, I still get 417 errors?

lp...@colada.com

unread,
Dec 26, 2008, 4:57:47 PM12/26/08
to Twitter Development Talk
From the doc on MSDN "Changing the value of this property does not
affect existing ServicePoint objects. Only new ServicePoint objects
created after the change are affected. "

Make sure the statement
System.Net.ServicePointManager.Expect100Continue = false; is called in
the service contrutor and you should be fine.
> > > <http://tommorris.org>- Hide quoted text -
>
> - Show quoted text -

Joint Contact

unread,
Jan 1, 2009, 3:06:06 PM1/1/09
to Twitter Development Talk
Thanks for posting this information. We've applied these changes and
our application is back to normal.

Regards;

-Wayne

Vivek

unread,
Jan 6, 2009, 7:49:15 AM1/6/09
to Twitter Development Talk
Hi,

We are getting same (417) error back in our website.

code:
public string ExecutePostCommand(string url, string userName, string
password, string data)
{
WebRequest request = WebRequest.Create(url);
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty
(password))
{
request.Credentials = new NetworkCredential(userName,
password);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";

if (!string.IsNullOrEmpty(TwitterClient))
{
request.Headers.Add("X-Twitter-Client",
TwitterClient);
}

if (!string.IsNullOrEmpty(TwitterClientVersion))
{
request.Headers.Add("X-Twitter-Version",
TwitterClientVersion);
}

if (!string.IsNullOrEmpty(TwitterClientUrl))
{
request.Headers.Add("X-Twitter-URL",
TwitterClientUrl);
}

if (!string.IsNullOrEmpty(Source))
{
data += "&source=" + HttpUtility.UrlEncode(Source);
}

byte[] bytes = Encoding.UTF8.GetBytes(data);

request.ContentLength = bytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);

System.Net.ServicePointManager.Expect100Continue =
false;
using (WebResponse response = request.GetResponse())
{
using (StreamReader reader = new StreamReader
(response.GetResponseStream()))
{
return reader.ReadToEnd();
}
}
}
}

return null;
}

Please help me out,

Thanxs

Vivek Shrivastav
> > your request to get past this issue.- Hide quoted text -

Maxfield Pool

unread,
Jan 6, 2009, 9:01:32 AM1/6/09
to twitter-deve...@googlegroups.com
Try moving your System.Net.ServicePointManager.Expect100Continue = false higher in your method before you create your WebRequest object, that should help.

Vivek

unread,
Jan 7, 2009, 8:21:52 AM1/7/09
to Twitter Development Talk
Hi,

thanxs for replying, i have tried as per you mention.

But no success, still getting (417) error.

Vivek Shrivastav
Invitratech India
> > > - Show quoted text -- Hide quoted text -

ErikAkerfeldt

unread,
Feb 23, 2009, 9:51:27 AM2/23/09
to Twitter Development Talk
Hi,

I had some trouble with this. My app were making two webrequests, to
two different servers.
The first one never experiences any issues with the 417 error and I
added 100Cont = false to all my Twitter requestes.

it turned out,

My app needed
System.Net.ServicePointManager.Expect100Continue = false
on all webrequests not only those going to Twitter

Then everything is fine. :)

sttester

unread,
Apr 23, 2009, 1:36:15 AM4/23/09
to Twitter Development Talk
Hi,

The '417- Expectation failed error' occurs again for me while updating
status. I am using the Yedda Twitter library. I have already added
'System.Net.ServicePointManager.Expect100Continue = false;' to my
Posting function:

protected string ExecutePostCommand(string url, string userName,
string password, string data)
{

WebRequest request = WebRequest.Create(url);
if (!string.IsNullOrEmpty(userName) && !
string.IsNullOrEmpty(password))
{
request.Credentials = new NetworkCredential(userName,
password);
request.ContentType = "application/x-www-form-
urlencoded";
request.Method = "POST";
System.Net.ServicePointManager.Expect100Continue =
false;

etc etc.............


I tried changing the position of
'System.Net.ServicePointManager.Expect100Continue = false;' to above
the WebRequest object creation, but that also does n't help.

This occurs in random. Please help me out of this situation as this
has been happening since a week now.

Thanks in advance
Reply all
Reply to author
Forward
0 new messages