How do I make Invoke-RestMethod print the response body as is
First of all, the -Method
and -ContentType
you are providing are the default, you can drop those. And to get the json, cast it back to json.
Invoke-RestMethod -Uri "http://example.com/" | ConvertTo-Json -Depth 10
I have no idea why you want to cast back to json, but well, here you go.
The other answer works great for JSON responses, but the -UseBasicParsing switch works for any response type:
(Invoke-WebRequest -UseBasicParsing -Uri 'http://example.com').Content
will give you just the response content (in the example.com case, the raw html, or in your use case, the raw JSON).