我可以使用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'