文章摘要
这篇文章介绍了一个使用curl命令和简单脚本来自动化获取API token并完成后续请求的方法。文章详细说明了从配置API URL开始,通过curl获取token的流程,包括使用`curl --location --request GET`获取token,并通过`echo $token`提取和处理token值。接着,文章展示了如何使用处理后的token,通过curl命令完成POST请求,提交设备运行数据。文章重点突出了API调用的基本流程和代码实现。
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 ”
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 ”
© 版权声明
文章版权归作者所有,未经允许请勿转载。