Json 调用RestMethod Powershell V3内容类型
我能够使用powershell v5中的JIRA rest API。但是,相同的代码在powershell v3中抛出以下错误Json 调用RestMethod Powershell V3内容类型,json,rest,powershell,Json,Rest,Powershell,我能够使用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([Syste
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'
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'