MicrosoftDocs / PowerShell-Docs

The official PowerShell documentation sources
https://learn.microsoft.com/powershell
Creative Commons Attribution 4.0 International
1.93k stars 1.55k forks source link

Explain URL encoding when passing query parameters to body #11155

Closed Nova1089 closed 1 month ago

Nova1089 commented 1 month ago

Prerequisites

Links

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.4 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.4

Summary

This applies to both Invoke-RestMethod and Invoke-WebRequest.

When passing query parameters as an argument to "Body" on a "Get" call, this cmdlet automatically URL encodes the query parameters. Please mention this. Please also explain that it encodes spaces with + signs instead of %20. This is important to note because not all APIs will accept this encoding. On verbose this cmdlet does not show you the payload it's sending to the API, so this is a massive headache to troubleshoot, as you can only learn this by inspecting the payload with your own HTTP listener.

Details

No response

Suggested Fix

No response

Nova1089 commented 1 month ago

Thanks for the update to the docs, the added hyperlinks to the UrlEncode() method reference are incorrect though.