开发者

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

开发者 https://www.devze.com 2023-03-05 03:18 出处:网络
In the do_POST() method of BaseHTTPRequestHandler I can开发者_Python百科 access the headers of the POST request simply via the property self.headers. But I can\'t find a similar property for accessing

In the do_POST() method of BaseHTTPRequestHandler I can开发者_Python百科 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?


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号