Forum Discussion
Danny_B855
Jun 10, 2020Copper Contributor
REST API Request Using Invoke-RestMethod
I'm having a devil of time formatting a request to a REST API. I've tried twenty different ways of passing the request information in headers\body using Invoke-RestMethod. Here's what the request ne...
Danny_B855
Copper Contributor
Danny_B855Here's the last thing I tried:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", 'Basic ' + $encodedCreds)
$headers.Add("Content-Type", "application/octet-stream`r`n<show system uptime>`r`n<show system version>")
$Response = Invoke-RestMethod "https://1.2.3.4/api/v1/files/cliScript/incremental" -Headers $headers -Method Put
Error:
Invoke-RestMethod : Specified value has invalid CRLF characters.
VasilMichev
Jun 11, 2020MVP
You seem to be passing them as header values, try it with the body of the request instead.