【问题标题】:webapp2 how to access PUT datawebapp2如何访问PUT数据
【发布时间】:2018-04-13 15:57:02
【问题描述】:

我正在使用webapp2做一个小api。

例如,如果我有:

import webapp2

class Test(webapp2.RequestHandler):

    def put(self):
        self.response.write("this was a test")

app = webapp2.WSGIApplication([
    ('/test', Test)
])

我通过 curl 发出请求:

curl --request PUT --header "Content-Type: application/json" --data '{"content": "test"}' http://localhost:8080/test

我将如何访问传入的数据'{"content": "test"}'

【问题讨论】:

    标签: json python-2.7 httprequest put webapp2


    【解决方案1】:

    所有请求数据都在self.request 中的某个位置,因此在这种情况下,请查看self.request.body 以查找请求的内容并查看文档的Common Request attributes 部分以查看其余选项。

    您可能还想考虑在调试器中查看整个 self 对象,以了解它具有的更多有趣属性。

    【讨论】:

      猜你喜欢
      • 2012-10-07
      • 2016-08-19
      • 1970-01-01
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      相关资源
      最近更新 更多