在Powershell中获取API响应时遇到问题

时间:2019-05-23 08:08:06

标签: powershell api response

我试图创建一个Powershell脚本来检查我的API是否正常工作。我可以使用Invoke-RestMethod来访问API,没有任何问题,但是我无法获得API响应。

我尝试了Invoke-RestMethod和Invoke-WebRequest

$user = 'User'
$pass = 'Test123'

$pair = "$($user):$($pass)"

$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

$basicAuthValue = "Basic $encodedCreds"

$Headers = @{
    Authorization = $basicAuthValue
}
$url="MYAPIURL"

$person = @{
    UserID='test'
    Password='Test123'
}
$json = $person | ConvertTo-Json


$Result =Invoke-RestMethod -Uri $url -Headers $Headers  -Body $json -Method Post -ContentType 'application/json'

Write-Host ($Result | Format-Table | Out-String)

$Result中总是空白。在邮递员中,它工作正常。

0 个答案:

没有答案
相关问题