Azure Rest api AuthenticationFailedInvalidHeader

标签 azure

我正在调用 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/

相关文章:

azure - 命名实体识别 - 我们是否需要外部列表来匹配结果?

c# - 加载X509证书: Error in Azure,无法在本地重现

java - 从 azure 广告中的重定向uri获取 token

azure - 在没有错误消息的情况下,如何确定为什么在 `az fs upload` 中没有发生文件上传?

Azure Functions -> 无法将 IServiceProvider 或 IFunctionsHostBuilder 注入(inject)工厂类构造函数

azure - 使用 Azure cli/PowerShell 获取 Cosmos DB 帐户主帐户 key /主连接字符串

c# - ImageResizer.Net AzureReader2 插件无法正常工作

c# - Azure表存储跨多个分区批量插入?

c# - 无法加载文件或程序集 FSharp.Core,版本=4.0.0.0 Azure Web 角色

azure - 由于缺少一个或多个强制参数,无法处理命令 : ServicePrincipalId ServicePrincipalPass ServicePrincipalTenant AcrName