Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract HTTP message body in BaseHTTPRequestHandler.do_POST()?

In the do_POST() method of BaseHTTPRequestHandler I can access the headers of the POST request simply via the property self.headers. But I can't find a similar property for accessing the body of the message. How do I then go about doing that?

like image 813
Frederick The Fool Avatar asked May 12 '11 09:05

Frederick The Fool


1 Answers

You can access POST body in do_POST method like this:

for python 2

content_len = int(self.headers.getheader('content-length', 0))

for python 3

content_len = int(self.headers.get('Content-Length'))

and then read the data

post_body = self.rfile.read(content_len)
like image 107
Roman Bodnarchuk Avatar answered Nov 06 '22 22:11

Roman Bodnarchuk