使用curl进行post请求,在json数据中添加变量

使用curl进行post请求,在json数据中添加变量
参数:

-X :定义请求方式
-H:添加请求头
-d: 添加请求的数据

添加json数据
方法一
curl -X POST -H "Content-Type: application/json" -d '{"field":"data"}' https://example.com
方法二
curl -X POST -H "Content-Type: application/json" -d "{\"field\":\"data\"}" https://example.com


有时候我们的json数据并不是写死的,需要把参数传进去改怎么做呢?


在json数据中添加变量
方法一
uuid = "dadfahfafa"
curl -X POST -H "Content-Type: application/json" -d '{"field":"data","uuid":"'$uuid'"}' https://example.com

方法二

uuid = "dadfahfafa"
curl -X POST -H "Content-Type: application/json" -d "{\"field\":\"data\",\"uuid\":\"$uuid\"}" https://example.com

posted @   zyl88  阅读(271)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示