Expect: 100-continue

bish0p

Member
Licensed User
Longtime 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
 

agraham

Expert
Licensed User
Longtime 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.

B4X:
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.
B4X:
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.
 

bish0p

Member
Licensed User
Longtime User
That would be disappointing as it is on the device that I want the app to work :(
 

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?
 

Cableguy

Expert
Licensed User
Longtime 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
 

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
 

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
 

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"
 
Top