gpt4 book ai didi

json - Invoke-RestMethod Powershell V3内容类型

转载 作者:行者123 更新时间:2023-12-03 00:34:50 25 4
gpt4 key购买 nike

我可以使用Powershell v5中的JIRA rest API。但是,相同的代码在Powershell v3中引发以下错误。

WARNING: Remote Server Response: The 'Content-Type' header must be modified using the appropriate property or method.

源代码
$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
$headers = @{
"Authorization" = $basicAuth
"Content-Type"="application/json"
}

$response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $body

最佳答案

Invoke-Restmethod具有-ContentType参数,因此错误似乎表明您应该使用它来指定内容类型,而不是通过headers参数传递它:

$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
$headers = @{
"Authorization" = $basicAuth
}

$response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $body -ContentType 'application/json'

关于json - Invoke-RestMethod Powershell V3内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44607806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com