使用powershell连接到azure rest api,导致StatusCode:203 StatusDescrip



我可以使用poster中的PAT令牌将fine连接到azure API,但无法使用powershell进行身份验证。

在尝试了不同的授权传递后,我仍然无法返回登录的html页面。这是我正在进行的样品请求

Invoke-RestMethod https://feeds.dev.azure.com/xx/x/_apis/packaging/Feeds/x/Packages -Headers @{Authorization="Token :xxx"}

经过多次搜索,我发现https://www.opentechguides.com/how-to/article/azure/201/devops-rest-powershell.html.下面是一个简化的片段,它使我的请求能够成功通过。

#enter your token in pat token
$pat = "xxx"
# Create header with PAT
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($pat)"))
$header = @{authorization = "Basic $token"}
#enter your url in projects url
$projectsUrl = "https://feeds.dev.azure.com/xx/x/_apis/packaging/Feeds/x/Packages -Headers"
$projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -ContentType "application/json" -Headers $header

最新更新