Reputation: 2029
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
Upvotes: 5
Views: 26723
Reputation: 23395
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'
Upvotes: 9