views:

576

answers:

3

I can't seem to figure this one out. No matter what I do, I keep getting a "417 Expectation failed" error. Everywhere I've looked says that I need to get rid of the Expect header for the HttpWebRequest. Setting the static property ServicePointManager.Expect100Continue = false or the instance property on the web request request.ServicePoint.Expect100Continue = false never get's rid of the header. I have to manually set it to null to remove it.

No matter what though, I STILL get the 417 error. What am I missing?

private static readonly MessageReceivingEndpoint UpdateStatusEndpoint 
       = new MessageReceivingEndpoint("http://twitter.com/statuses/update.xml", HttpDeliveryMethods.PostRequest);

public static XDocument UpdateStatus(ConsumerBase twitter, string accessToken, string message)
{
    var data = new Dictionary<string, string>();
    data.Add("status", message);
    ServicePointManager.Expect100Continue = false; //Doesn't work
    HttpWebRequest request = twitter.PrepareAuthorizedRequest(UpdateStatusEndpoint, accessToken, data);

    request.ServicePoint.Expect100Continue = false; //setting here doesn't work either

    //request.Expect is still set at this point unless I explicitly set it to null.

    request.Expect = null;
    var response = twitter.Channel.WebRequestHandler.GetResponse(request); //Throws exception
    return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
}
A: 

LinqToTwitter is a Twitter client library that uses DotNetOpenAuth. I'll see about adding a message posting example to the DotNetOpenAuth core library for a future version.

Andrew Arnott
+1  A: 
Antonio
A: 

DotNetOpenAuth doesn't set or support Except100Continue directly. Would be nice if there is a property in the Channel class.

Add this before your call to 'PrepareAuthorizedRequest':

    ((HttpWebRequest)WebRequest.Create
(UpdateStatusEndpoint.Location)).ServicePoint.Expect100Continue = false;

Except100Continue is set depending on the called URL. So you can set it before the connection is created. You may even set it globally in the config file.

  <system.net>
    <settings>
      <servicePointManager expect100Continue="false" />
    </settings>
  </system.net>
EricSch
DotNetOpenAuth just uses the HttpWebRequest class, so Eric, what is it that DotNetOpenAuth doesn't support about the Expect100Continue setting?
Andrew Arnott
A perhaps cleaner way to set the Twitter's ServicePoint.Expect100Continue property would be `ServicePointManager.FindServicePoint(UpdateStatusEndpoint.Location).Expect100Continue = false`
Andrew Arnott
Andrew, I was thinking at the property: webRequest.ServicePoint.Expect100Continue = false; But after some rethinking, I assume, it doesn't matter. Both will probably contact the ServicePointManager.
EricSch
It would be perhaps more obvious via webrequest.
EricSch