调用RestMethod Powershell V3 Content-Type

4

我能够在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
1个回答

9

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

$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'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接