Message159915
httplib doesn't specify the HTTP header 'content-length' for POST requests without data. Conceptually this makes sense, considering the empty content. However, IIS (7.5) servers don't accept such requests and respond with a 411 status code. See this question on StackOverflow for reference: http://stackoverflow.com/questions/5915131/can-i-send-an-empty-http-post-webrequest-object-from-c-sharp-to-iis.
See also issue #223 of the Requests project, https://github.com/kennethreitz/requests/issues/223, which regards this problem in the context of the requests Python library.
The following code makes a data-less POST request to the HTTP sniffer Fiddler running on localhost:
import httplib
conn = httplib.HTTPConnection("localhost", 8888)
conn.request("POST", "/post", "", {})
conn.close()
Fiddler reports that it receives the following headers for the POST request, as you can see 'content-length' is not included:
POST http://localhost:8888/post HTTP/1.1
Host: localhost:8888
Accept-Encoding: identity |
|
Date |
User |
Action |
Args |
2012-05-04 10:06:44 | Arve.Knudsen | set | recipients:
+ Arve.Knudsen |
2012-05-04 10:06:43 | Arve.Knudsen | set | messageid: <1336126003.87.0.468277340816.issue14721@psf.upfronthosting.co.za> |
2012-05-04 10:06:43 | Arve.Knudsen | link | issue14721 messages |
2012-05-04 10:06:42 | Arve.Knudsen | create | |
|