How to get POSTed JSON in Flask?

前端 未结 10 1144
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 06:35

I\'m trying to build a simple API using Flask, in which I now want to read some POSTed JSON. I do the POST with the Postman Chrome extension, and the JSON I POST is simply <

10条回答
  •  囚心锁ツ
    2020-11-21 07:11

    You may note that request.json or request.get_json() works only when the "Content-type: application/json" has been added in the header of the request. If you are unable to change the client request configuration, so you can get the body as json like this:

    data = json.loads(request.data)
    

提交回复
热议问题