postman-code-generators
postman-code-generators copied to clipboard
[PowerShell] The body parameter of Invoke-RestMethod should be null, not an emtpy string when using Get requests.
Describe the bug When doing a Get request, with an empty body and using the "PowerShell - RestMethod" code snippet, an error will be raised as the Invoke-Request method is improperly called.
To Reproduce
- Create a Get request to any ressource, say "example.com". The code generated will be:
$body = ""
$response = Invoke-RestMethod 'https://example.com/' -Method 'GET' -Headers $headers -Body $body
$response | ConvertTo-Json
The error returned by Powershell is the following:
Invoke-RestMethod : コンテンツ本体をこの verb-type では送信できません。
発生場所 行:3 文字:6
+ $a = Invoke-RestMethod 'https://example.com/' -Method 'GET' -Headers ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], ProtocolViolationException
+ FullyQualifiedErrorId : System.Net.ProtocolViolationException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Expected code snippet and corresponding request This snippet instead works:
$body = $null
$response = Invoke-RestMethod 'https://example.com/' -Method 'GET' -Headers $headers -Body $body
$response | ConvertTo-Json
Additional context Version of postman-code-generators/Postman app: 7.14.0
@JeromeLefebvre I am not able to reproduce this. The request goes fine for Powershell v7.
@JeromeLefebvre closing this issue as we couldn't reproduce it. Feel free to re-open if you are still facing this issue 🙇♂