×

linux json中设置变量

hqy hqy 发表于2024-03-11 00:48:55 浏览548 评论0

抢沙发发表评论

今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来

如下

curl -i -X POST -H ‘Content-type’:‘application/json’ -d {“BTime”:""$btime""} http://api.baidu.com
变量没有做解析

原来在shell中,"" '还是有很大区别的,

把修改后的curl发送贴出

复制代码
atime=date -d "$1" +%s

btime=date -d "$2" +%s

curl -i -X POST -H “‘Content-type’:‘application/json’” -d ‘{“ATime”:"‘a t i m e ′ " , " B T i m e " : " ′ atime'","BTime":"'atime","BTime":"btime’"}’ $url

需要注意的是,json数据里变量要用 ’ ’ 括起来




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://sg.hqyman.cn/post/5382.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏

群贤毕至

访客

您的IP地址是: