Invoke-RestMethod Powershell V3 Content-Type

I am able to use the JIRA rest API from powershell v5. However the same code throws the below error in powershell v3.

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

Source Code

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

  • answered 2017-06-17 18:08 Mark Wragg

    Invoke-Restmethod has a -ContentType parameter, so the error seems to be indicating you should use that to specify Content Type instead of passing it via the headers parameter:

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