【问题标题】:Get full raw http request (complete with headers and body)获取完整的原始 http 请求(包含标头和正文)
【发布时间】:2013-11-13 20:39:46
【问题描述】:

在一个 appengine 项目中,我试图在 webapp2.RequestHandler 中获取整个 http 请求:

class ConnectedHandler(webapp2.RequestHandler):
def post(self):        
    logging.info("Someone connected: " + self.request.get('from'))
    # How to get the raw http request from self.request? 

查看文档后我开始认为这是不可能的

我正在寻找的结果是这样的(无论如何我都会称之为 http 请求):

POST /6473924464345088 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Type: application/json; charset=utf-8
Host: localhost:10083
User-Agent: HTTPie/0.3.0

{
    "u": "a"
}

编辑:更新示例

使用 webapp2 时是否有另一种更有效的方式来访问这些数据?

【问题讨论】:

    标签: python google-app-engine webapp2 webob


    【解决方案1】:

    这应该让你明白:

    class MainPage(webapp2.RequestHandler):
        def post(self):
            self.response.write('Just received:\n\n' + str(self.request))
    

    【讨论】:

      猜你喜欢
      • 2015-02-18
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 2018-08-08
      相关资源
      最近更新 更多