self.rfile.read(int(self.headers.getheader('Content-Length'))) returns the original HTTP POST data as a string.
Destruction:
- The 'Content-Length' header indicates how many bytes the HTTP POST data contains.
self.headers.getheader('Content-Length') returns the length of the content (header value) as a string.- This needs to be converted to an integer before passing as a parameter to
self.rfile.read() , so use the int() function.
Also, note that the header name is case sensitive, therefore it only has “Content-Length”.
Edit: Apparently, the header field is not case sensitive (at least in Python 2.7.5), which I believe is the correct behavior since https://tools.ietf.org/html/rfc2616 :
Each header field consists of a name followed by a colon (":") and a field value. Field names are case insensitive.
source share