[New-bugs-announce] [issue14721] httplib doesn't specify content-length header for POST requests without data
Arve Knudsen
report at bugs.python.org
Fri May 4 12:06:43 CEST 2012
New submission from Arve Knudsen <arve.knudsen at gmail.com>:
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
----------
components: Library (Lib)
messages: 159915
nosy: Arve.Knudsen
priority: normal
severity: normal
status: open
title: httplib doesn't specify content-length header for POST requests without data
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14721>
_______________________________________
More information about the New-bugs-announce
mailing list