IT码农库

您当前所在位置:首页 > 脚本专栏 > linux shell

linux shell

shell脚本发送http哀求的实现示例

[db:来源] 2023-04-28linux shell5304
本文主要介绍了shell脚本发送http哀求的实现示例,文中通过示例代码介绍的非常具体,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

简述:使用shell脚本发送http哀求,解析哀求获取token再次发起哀求

系统:ubuntu系统

工具:cURL(发送http哀求),jq(解析json),没有需要安装

host="192.168.1.199"
post="8888"
pre="/api/v1"
url_pre="http://${host}:${post}${pre}"
get_token="curl --location --request GET ${url_pre}/token?access_id=admin&access_secret=123456&="
echo $get_token
token=$($get_token)
echo $token
token=$(echo $token | jq  ".data.token")
token=${token:1:-1}
echo $token
curl --location --request POST ${url_pre}/device/runtime_data?token=${token} --header 'Content-Type: application/json' --data-raw '{"id_device": "d2217a3b-dfc0-4301-86f3-78fbb4cb58e4","data_type": ""}'

shell 调用HTTP POST哀求

curl -X POST --header 'Content-Type: application/json' --header 'ReportScript-Sign: FgPlfGlYw83zMdZd' --header 'Accept: application/json' -d '{                        
    "data": {                                                                                                                                                                                     
      "appkey": "XXXXX",                                                                                                                                                                          
      "code": "bigdata.platform.XXXXX",                                                                                                                                                            
      "params": {}                                                                                                                                                                                
    },                                                                                                                                                                                            
    "extra": {}                                                                                                                                                                                                                                                                                                                                                                             
  }' 'http://XX.XX.XX.XX:XXXXX/report_api/extraFunction/commonApi'

到此这篇关于shell脚本发送http哀求的实现示例的文章就介绍到这了,更多相关shell发送http哀求内容请搜索以前的文章或继承浏览下面的相关文章希望大家以后多多支持!

大图广告(830*140)