[英]Save CURL is output into a variable in batch file
嗨这是我的第一篇文章,所以如果我没有正确格式化或者不是主题,请告诉我。
我需要使用cURL来访问数据库并为存储在云中的每个设备提取数据点。 到目前为止,我的问题是如何从此行保存访问令牌:
`curl -X POST -d "<user><email>myemail@anexample.com</email><password>Passwordexample</password><application><app_id>anidexample_id</app_id><app_secret>asecretexample_secret</app_secret></application></user>" -H "Content-Type:application/xml" https://user.aylanetworks.com/users/sign_in.xml`
变成一个变量。
到目前为止我用过:
@echo off
set /p UserInput= Enter the Access Token:
@echo on
curl -H "Authorization: auth_token %UserInput%" https://ads-dev.aylanetworks.com/apiv1/dsns/AC000W000007000/properties.xml>TestFile.xml
这会传递令牌,但每次都需要手动输入。 我试图使用set而不需要用户输入,但我无法让它工作。 有没有设置变量我缺少的东西?
任何帮助将不胜感激,
DM
假设CURL的XML响应如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<authorization>
<access-token>0317080d361a430bb81e3997114267bf</access-token>
<refresh-token>c696753bddb4459c9a8ceb54fa04d53b</refresh-token>
<expires-in type="integer">86400</expires-in>
<role>OEM::Staff</role>
<role-tags type="array"/>
</authorization>
你可以试试 :
@echo off
set URL="<user><email>myemail@anexample.com</email><password>Passwordexample</password><application><app_id>anidexample_id</app_id><app_secret>asecretexample_secret</app_secret></application></user>"
for /f "skip=2 tokens=3 delims=^<^>" %%a in ('curl -X POST -d %URL% -H "Content-Type:application/xml" https://user.aylanetworks.com/users/sign_in.xml') do (
set "$token=%%a"
goto:next)
:next
echo The token is : %$token%
pause
curl -H "Authorization: auth_token %$token%" https://ads-dev.aylanetworks.com/apiv1/dsns/AC000W000007000/properties.xml>TestFile.xml
在发送第二个请求之前我推了一个PAUSE
,你可以检查%$token%
是否有正确的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.