使用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
浙公网安备 33010602011771号