linux shell中curl 發(fā)送post請(qǐng)求json格式問題的處理方法
更新時(shí)間:2018年07月03日 08:37:19 作者:Believer007
這篇文章主要介紹了linux shell中curl 發(fā)送post請(qǐng)求json格式問題的處理方法,文中給大家提到了linux中使用curl發(fā)送post請(qǐng)求問題,需要的朋友可以參考下
今天在linux中使用curl發(fā)送一個(gè)post請(qǐng)求時(shí),帶有json的數(shù)據(jù),在發(fā)送時(shí)發(fā)現(xiàn)json中的變量沒有解析出來
如下
curl -i -X POST -H 'Content-type':'application/json' -d {"BTime":""$btime""} http://api.baidu.com
變量沒有做解析
原來在shell中,"" '還是有很大區(qū)別的,
把修改后的curl發(fā)送貼出
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數(shù)據(jù)里變量要用''括起來
下面看下Linux 中使用 curl 發(fā)送 post 請(qǐng)求
curl -i -X POST -H 'Content-type':'application/json' -d '{"keyWord":"雅詩蘭黛","page":1,"pageSize":12,"sortFieldList":["isCombo|desc"]}' http://127.0.0.1:8015/search/prod/query
# 注意的是,json數(shù)據(jù)里變量要用 '' 括起來
總結(jié)
相關(guān)文章
Python執(zhí)行Linux系統(tǒng)命令的4種方法
這篇文章主要介紹了Python執(zhí)行Linux系統(tǒng)命令的4種方法,即在Python腳本中調(diào)用Shell命令,需要的朋友可以參考下2014-10-10

