如何在BaseHTTPRequestHandler.do_POST()中提取HTTP消息体? [英] How to extract HTTP message body in BaseHTTPRequestHandler.do_POST()?
本文介绍了如何在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 $中访问POST正文c $ c>这样的方法:
content_len = int(self.headers.getheader('content-length', 0))
post_body = self.rfile.read(content_len)
这篇关于如何在BaseHTTPRequestHandler.do_POST()中提取HTTP消息体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文