[Shell]curl请求一个带变量的POST请求,变量来自另一个程序的执行结果

2021-01-29 2630点热度 0人点赞 1条评论

在写Shell脚本的时候,遇到要把数据POST到服务器的时候,POST的数据可能是动态的或者是其他Shell执行的结果。

以POST JSON为例 (如果要POST FORM-DATA或其他的,参考 Linux Bash Curl Post的例子)

#注意=前后不要加空格
#一个普通变量的例子
name="xxx"
#另一个例子,msg的内容是执行另一个shell脚本的执行结果的输出,我们准备把输出发送给API
msg=$(/path/to/another_shell.sh 2>&1)
curl http://192.168.1.1:8182/api/notify  -H "Accept: application/json"  -H "Content-Type: application/json"  -d '{"msg":"'"$msg"'","name":"'"$name"'"}'

 

admin

这个人很懒,什么都没留下

文章评论

  • insinoSat

    Zentel With Free Shipping Pharmacy 36 hour cialis online Wdcxyp Candian Pharmacy Online Canada Mrizsd Amoxicillin And Pseudophedrine For Sinusitis cialis 40 mg

    2022-04-13
  • 您需要 登录 之后才可以评论