如何在BaseHTTPRequestHandler.do_POST()中提取HTTP消息体? [英] How to extract HTTP message body in BaseHTTPRequestHandler.do_POST()?

查看:343
本文介绍了如何在BaseHTTPRequestHandler.do_POST()中提取HTTP消息体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BaseHTTPRequestHandler do_POST()方法中,我只需通过属性即可访问POST请求的标题 self.headers 。但是我找不到用于访问消息正文的类似属性。那我怎么去做呢?

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?

推荐答案

你可以在 do_POST 这样的方法:

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

这篇关于如何在BaseHTTPRequestHandler.do_POST()中提取HTTP消息体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆