【发布时间】:2015-05-09 23:34:58
【问题描述】:
我有一个使用Flask 在Python 中运行的应用程序。
API 的端点如下所示:
@app.route('/postIt', methods =['POST'])
def postReview():
#print flask.request
if flask.request.method == 'POST':
posts = flask.request.get_json()
print posts
return str(posts)
我正在尝试使用CURL 发送请求:
curl http://127.0.0.1:5000/postIt -d @post.json -H "Content-Type: application/json"
post.json 看起来像这样:
{"post1":"3", "post2": "2", "post3":"3", "post4":"4" "post5": "5"}
这不是很好。服务器端的输出没有打印任何内容,表明它无法获取我发送的 json 文件。
我查看了-d flag of CURL,发现了这个东西:
The contents of the file must already be URL-encoded.
所以我猜肯定有encoding issues with my post.json 文件。我不完全知道应该在这里使用哪种编码。请帮忙!!
【问题讨论】: