今天在linux中使用curl發送一個post請求時,帶有json的數據,在發送時發現json中的變量沒有解析出來linux
以下shell
curl -i -X POST -H 'Content-type':'application/json' -d {"BTime":""$btime""} http://api.baidu.com
變量沒有作解析json
原來在shell中,"" '仍是有很大區別的,api
把修改後的curl發送貼出app
atime=`date -d "$1" +%s` btime=`date -d "$2" +%s` curl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'$atime'","BTime":"'$btime'"}' $url 須要注意的是,json數據裏變量要用''括起來