尝试确定如何在Azure CLI“rest”子命令的文本文件中捕获rest有效负载。
这是可行的:
az rest --method get --uri "https://prices.azure.com/api/retail/prices?$filter=serviceName eq 'Virtual Machines' and armRegionName eq 'westindia'"
但如果我将其保存在文本文件中,过滤器就不起作用了:
C:\Users\foo> type query.txt
$filter=serviceName eq 'Virtual Machines' and armRegionName eq 'westindia'
C:\Users\foo> az rest --verbose --method get --uri "https://prices.azure.com/api/retail/prices" --body @query.txt --headers Content-Type=text/plain
Can't derive appropriate Azure AD resource from --url to acquire an access token. If access token is required, use --resource to specify the resource
Request URL: 'https://prices.azure.com/api/retail/prices'
Request method: 'GET'
Request headers:
'User-Agent': 'python/3.10.5 (Windows-10-10.0.22000-SP0) AZURECLI/2.38.0 (MSI)'
'Accept-Encoding': 'gzip, deflate'
'Accept': '*/*'
'Connection': 'keep-alive'
'Content-Type': 'text/plain'
'x-ms-client-request-id': '<immaterial>'
'CommandName': 'rest'
'ParameterSetName': '--verbose --method --uri --body --headers'
'Content-Length': '74'
Request body:
$filter=serviceName eq 'Virtual Machines' and armRegionName eq 'westindia'
Response status: 200
Response headers:
'Content-Length': '10821'
'Content-Type': 'application/json; charset=utf-8'
'Date': 'Tue, 02 Aug 2022 11:24:55 GMT'
'Server': 'Microsoft-IIS/10.0'
'Cache-Control': 'no-cache'
'Content-Encoding': 'gzip'
'Expires': '-1'
'Pragma': 'no-cache'
'Set-Cookie': 'ARRAffinity=<immaterial>;Path=/;HttpOnly;Secure;Domain=prices.azure.com, ARRAffinitySameSite=<immaterial>;Path=/;HttpOnly;SameSite=None;Secure;Domain=prices.azure.com'
'Vary': 'Accept-Encoding'
'X-AspNet-Version': '4.0.30319'
'X-Powered-By': 'ASP.NET'
Response content:
{"BillingCurrency":"USD","CustomerEntityId":"Default","CustomerEntityType":"Retail","Items":[{"currencyCode":"USD","tierMinimumUnits":0.0,"retailPrice":0.1955,"unitPrice":0.1955,"armRegionName":"southindia", ...
为了简洁,响应被截断了。但是注意southindia
出现在响应中。很明显,过滤器不起作用。
我知道我的负载(query.txt
的内容)不是URL编码的。
如何从一个文件发送一个有效的过滤器负载?
不相关,但共享完整上下文:我正在尝试构建一个匹配SKU名称的过滤器。请参阅Find cheapest spot supported size / sku via az CLI or terraform provider
1条答案
按热度按时间3phpmpom1#
无法通过外部文本文件发送有效负载。请参阅https://github.com/Azure/azure-cli/issues/23465#issuecomment-1364631686。