Fre*_*ool 44 python post http basehttpserver basehttprequesthandler
在我的do_POST()方法中,BaseHTTPRequestHandler我只需通过属性访问POST请求的标题self.headers.但是我找不到用于访问消息正文的类似属性.那我怎么去做呢?
Rom*_*huk 88
您可以使用以下do_POST方法访问POST正文:
对于python 2
content_len = int(self.headers.getheader('content-length', 0))
Run Code Online (Sandbox Code Playgroud)
对于python 3
content_len = int(self.headers.get('Content-Length'))
Run Code Online (Sandbox Code Playgroud)
然后读取数据
post_body = self.rfile.read(content_len)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34953 次 |
| 最近记录: |