Expect: 100-continue

Discussion in 'Questions (Windows Mobile)' started by bish0p, Jan 13, 2009.

  1. bish0p

    bish0p Member Licensed User

    I have been using the HTTP library now for some time, and have noticed that is always adds the "Expect: 100-continue" header when it is sending a request.

    It has not been an issue as it has been ignored by the site I am using, however they are now responding to the header with an error, so I am wondering how I stop the Header from being added in the first place.

    Thanks
     
  2. agraham

    agraham Expert Licensed User

    I don't really do Web stuff but I poked around in the .NET HttpWebRequest class and it is being added deep within the bowels of that class in a method called SerializeHeaders() that seems to build the headers for the request.

    Code:
    ExpectContinue = (ExpectContinue && !IsVersionHttp10) && ServicePoint.Expect100Continue;
    if (((ContentLength > 0L) || (HttpWriteMode == HttpWriteMode.Chunked)) && ExpectContinue)
    {
        _HttpRequestHeaders.AddInternal(
    "Expect""100-continue");
    }
    Googling around other have come across this problem HttpWebRequest and the Expect: 100-continue Header Problem that afflicts Http 1.1 - see the test for version info in the code above.

    The answer on the desktop would be to get the .NET WebRequest object from your Basic4ppc WebRequest object, get it's ServicePoint and set its Expect100Continue property to false.
    Code:
    webRequest.ServicePoint.Expect100Continue = false;
    This is probably possible with the Door library. However this won't work on the device as ServicePoint doesn't expose this property in the Compact Framework so I guess the only thing is to roll your own Http requests using TCP/IP and the Network library.
     
  3. bish0p

    bish0p Member Licensed User

    That would be disappointing as it is on the device that I want the app to work :(
     
  4. ChrisOrton

    ChrisOrton Member Licensed User

    A gentle nudge to see if anyone has any more ideas on this.

    Today I returned to my app designed to do twitter updates And found the above problem accessing the twitter api with http request objects

    Alternatively are there any examples of rolling your own http requests?
     
  5. Cableguy

    Cableguy Expert Licensed User

    peek a bit in the cs file of the http dll....
    I kind of remember, the last time I done that, that in the constructor, some header were pre-defined...but I may be wrong here..
    If so, create a new project in sharp develop, and create you're own custom http dll...but be sure to ask EREL for perrmission...lol
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    As agraham wrote this header is added in a lower level. Not in Http.dll code.
    So it will not help here.
     
  7. ChrisOrton

    ChrisOrton Member Licensed User

    Thanks for the input, I've got a quick work round by putting the parameters in the request url

    Not sure thats entirely right, but I'll have another play tomorrow I'm having difficulty getting it to compile on the device right now
     
  8. Cableguy

    Cableguy Expert Licensed User

    You mean FOR the device, right?
     
  9. ChrisOrton

    ChrisOrton Member Licensed User

    LOL

    Yes, for the device, been a long day
     
  10. ChrisOrton

    ChrisOrton Member Licensed User

    I've been accessing the twitter api and after a change by twitter sometime in December started getting expectation failed errors caused by "Expect: 100-continue" in the http headers.

    I've got a work around that solves the problem at least in my case

    as follows

    Old Code
    Sub Button2_Click
    request.New3(" http://twitter.com/statuses/update.xml","username","password")
    request.Method = "POST"
    Request.ContentType = "application/x-www-form-urlencoded"
    stream.New1(Request.GetStream,True)
    tweet = TextBox2.Text
    name = "status="&tweet
    stream.WriteBytes(stream.StringToBytes(name))
    response.New1
    request.GetAsyncResponse
    End Sub


    New Code
    Sub Button2_Click

    tweet = TextBox2.Text
    theurl = "http://twitter.com/statuses/update.xml?status="&tweet

    response.New1
    request.New3(theurl,"username","password")
    request.Method = "POST"
    Request.ContentType = "application/x-www-form-urlencoded"

    request.GetAsyncResponse
    End Sub


    A bit slow posting this as I forgot to install the latest http libray and that was causing compilation errors when I tried compiling FOR the device
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    I think you should use request.Method = "GET" (the default value). It seems that you don't pass any data in the post stream.
     
  12. ChrisOrton

    ChrisOrton Member Licensed User

    Just looking at the code, I'd agree the "GET" would be appropriate but...

    The twitter API specifies "POST" and trying to use "GET" the server returns a "bad request error"
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice