我正在调用 Azure 的 REST API 以从 SOAPUI 获取“列出某个区域中所有可用的虚拟机大小”,但它给出了错误响应。 {“错误”: { “代码”:“AuthenticationFailedInvalidHeader”, "message": "身份验证失败。'授权' header 以无效格式提供。" }} 我也设置了授权 header ..
最佳答案
API需要身份验证,因此您需要为SoapUI配置客户端证书身份验证。你的api没有问题。我使用 powershell 成功测试了您的 api。
Add-Type -Path 'C:\Program Files\Microsoft Azure Active Directory Connect\Microsoft.IdentityModel.Clients.ActiveDirectory.dll'
$context = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext ("https://login.windows.net/tenantid/")
$cred = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential ("clintid", "key")
$result = $context.AcquireToken("https://management.core.windows.net/", $cred)
$token = $result.AccessToken
$authHeader = "Bearer $token"
#$authHeader
$headers = @{"Authorization"=$authHeader; "Content-Type"="application/json"}
$size=Invoke-RestMethod -Method get -Uri "https://management.azure.com/subscriptions/subscriptionsid/providers/Microsoft.Compute/locations/location/vmSizes?api-version=2015-05-01-preview" -Headers $headers
$size.value
关于Azure Rest api AuthenticationFailedInvalidHeader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37409020/