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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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)