将 curl POST 请求转换为 curl JSON POST 请求

时间:2021-02-11 15:36:47

标签: json curl post

我正在使用这个 curl 行,以便触发对我的服务器的 POST 请求:

curl --data "item=my_item&is_done=true" 127.0.0.1:5000/convert

如何转换卷曲线,以发送相同的参数,但通过 JSON?

1 个答案:

答案 0 :(得分:1)

您可以使用以下命令

curl -d ‘{“item”: “my_item”, “is_done”: “true”}’ -H “Content-Type: application/json” -x POST 127.0.0.1:5000/convert

如果您想在文件 abcd.json 中共享参数,则

curl -d “@abcd.json” -H “Content-Type: application/json” -x POST 127.0.0.1:5000/convert