linux shell中curl 发送post请求json格式问题的处理方法
今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来
如下
curl-i-XPOST-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-XPOST-H"'Content-type':'application/json'"-d'{"ATime":"'$atime'","BTime":"'$btime'"}'$url
需要注意的是,json数据里变量要用''括起来
下面看下Linux中使用curl发送post请求
curl-i-XPOST-H'Content-type':'application/json'-d'{"keyWord":"雅诗兰黛","page":1,"pageSize":12,"sortFieldList":["isCombo|desc"]}'http://127.0.0.1:8015/search/prod/query #注意的是,json数据里变量要用''括起来
总结