【问题标题】:connecting to azure rest api using powershell resulting in StatusCode : 203 StatusDescription : Non-Authoritative Information使用 powershell 连接到 azure rest api 导致 StatusCode:203 StatusDescription:Non-Authoritative Information
【发布时间】:2022-10-15 05:14:41
【问题描述】:
我可以在邮递员中使用 PAT 令牌很好地连接到 azure API,但是无法使用 powershell 进行身份验证。
在尝试了不同的授权通过后,我仍然无法获得返回登录的 html 页面。这是我正在提出的示例请求
Invoke-RestMethod https://feeds.dev.azure.com/xx/x/_apis/packaging/Feeds/x/Packages -Headers @{Authorization="Token :xxx"}
【问题讨论】:
标签:
azure
powershell
api
invoke-restmethod
【解决方案1】:
经过大量搜索,我遇到了https://www.opentechguides.com/how-to/article/azure/201/devops-rest-powershell.html。这是一个简化的 sn-p,它允许我的请求成功通过。
#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