Search This Blog

Friday, June 10, 2011

HTTP/1.1 100 CONTINUE - While POSTing data to web server using curl

I have being trying to build a wrapper code to upload my applications/games on a famous appstore www.mobango.com

One problem which consume a lot of my bandwidth & worth mentioning is the "HTTP/1.1 100 CONTINUE" response headers from the web server while i was posting some variables & uploading files simultaneously.

After much searching I found an excellent blog on the issue, click Here to read the detailed blog.

Analyzing the TCP packets tell you that curl has set the HTTP Expect header as "Expect: 100-continue"

Removing the Expect header allowed curl to send an HTTP 1.1 POST, with its payload, before the server generated HTTP 1.0 302 FOUND.  The fact that the server responded with 302 FOUND means the entire POST data was ignored on the server side, but the client DID send it!  In other words, we just wasted some bandwidth, and we are going to need to POST the data at least one more time.  When curl was expecting an HTTP 1.1 100 CONTINUE instead, it never sends the rest of the payload, and curl never complains, not even with -v.


Conclusion
What is the takeaway message from all of this?  If you’re using curl to test your REST interface, then make sure you are aware of the behavior HTTP 1.1 100 CONTINUE.  You might notice it because your server receives a blank POST payload.  Your HTML forms will appear to have not been filled in, even though you specified one or more -F arguments on the curl command line.

The solution for the versions of curl I’ve tested is to either remove the Expect header, or to tell curl to use HTTP 1.0 (since curl will default to 1.1 otherwise).  Once again, here are those examples:

curl -H "Expect:" -F name=somevalue http://osx.example.com:8000
curl -0 -F name=somevalue http://osx.example.com:8000
This forces curl to POST the payload without waiting for the 100 CONTINUE response, and it is suitable for servers that don’t know how to provide a 100 CONTINUE.  I hope this helps someone out there to avoid the trouble I had debugging my wrapper interface.

No comments:

Post a Comment