【发布时间】:2016-01-10 05:24:42
【问题描述】:
我的flask代码如下:
@app.route('/sheets/api',methods=["POST"])
def insert():
if request.get_json():
return "<h1>Works! </h1>"
else:
return "<h1>Does not work.</h1>"
当请求是:
POST /sheets/api HTTP/1.1
Host: localhost:10080
Cache-Control: no-cache
{'key':'value'}
结果是<h1>Does not work.</h1>。
当我添加了Content-Type 标头时:
POST /sheets/api HTTP/1.1
Host: localhost:10080
Content-Type: application/json
Cache-Control: no-cache
{'key':'value'}
我收到 400 错误。
我做错了什么?
【问题讨论】: