我在尝试在 PowerShell 7 中使用 Invoke-RestMethod 命令时遇到了问题。我可以让它在 PowerShell 5.1 中正常运行,但 7 给了我一个 401 - Unauthorized 消息。
这是 PowerShell 5.1 的命令:
Invoke-RestMethod "http://internalServer/api/job?name=testJob" -Method GET -UseDefaultCredentials -ContentType "application/JSON"
这是 PowerShell 7 的命令:
Invoke-RestMethod "http://internalServer/api/job?name=testJob" -Method GET -UseDefaultCredentials -ContentType "application/JSON" -AllowUnencryptedAuthentication
api 托管在使用 Windows 身份验证的内部服务器上。当我通过 Fiddler 跟踪请求时,这两个命令似乎都得到了 401 响应,但 PowerShell 5.1 使用该响应生成 Authorization: Negotiate YII{token} 标头,而 PowerShell 7 停止并返回错误。有没有其他人遇到过这个?