我有一个应用程序运行在Python
中,使用Flask
。你知道吗
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
文件。我不知道这里应该用哪种编码。请帮忙!!你知道吗
当我尝试你的代码时,我得到了
400 Bad Request
:然后我发现你的json文件实际上是无效的。在
post4
和post5
之间缺少,
。修好后,我得到了正确的回答:相关问题 更多 >
编程相关推荐