Invoke-RestMethod Powershell V3 Content-Type
15,503
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'
Author by
Sudheej
Developer, OPS and Systems Engineer. In love with JavaScript, Python, Bash, and Powershell Skilled in Kubernetes, Openshift, SpringBoot, and Docker
Updated on June 13, 2022Comments
-
Sudheej almost 2 years
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