Ubuntu shell 里面,curl 命令用POST 请求 JSON, 老是返回bad request,看起来是参数错了,但是检查好几遍没发现错在哪…

以下代码老是报错400,bad request.

Curl -H "Authorization: Bearer yeirorfjfjfkfkfjfkeifchdjd" -H "Content_Type: application json" -d '{"awbNo": "4444444444"}' http://abccom

实在看不出哪里有错?

如果要在 a 中传递数据,curl则需要将参数格式化为查询字符串。它不会为您解码 JSON。你有几个选择,
修复卷曲:
(注意,我对每个参数都进行了编码)
重新格式化 curl 以使用 GET 参数:

curl 'http://127.0.0.1:5000/?query=SELECT%20COUNT(*)%20FROM%20usage'

按预期将 curl 重新格式化为 POST:


curl -H "Content-Type: application/json" -X POST http://127.0.0.1:5000/ -d 'query=SELECT%20COUNT(*)%20FROM%20usage'


这将让您在编写时获得上面的数据。
解析 JSON
这将让您在编写 cURL 时继续使用它:

# this is the short version, provided by randomir in the comments.
query = request.json().get('query')

# This is an alternative which roughly does the same thing
dat_str = request.data
dat_dict = json.loads(dat_str)
query = dat_dict['query']

你把对接文档发出来

http://url.com是个什么玩意
你不应该把你自己网站的网址替换进url里吗,你直接访问这玩意能返回正确才见鬼了