postman-code-generators icon indicating copy to clipboard operation
postman-code-generators copied to clipboard

[PowerShell] The body parameter of Invoke-RestMethod should be null, not an emtpy string when using Get requests.

Open JeromeLefebvre opened this issue 6 years ago • 1 comments

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

  1. 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 avatar Dec 27 '19 04:12 JeromeLefebvre

@JeromeLefebvre I am not able to reproduce this. The request goes fine for Powershell v7.

webholik avatar Oct 23 '20 04:10 webholik

@JeromeLefebvre closing this issue as we couldn't reproduce it. Feel free to re-open if you are still facing this issue 🙇‍♂

akshaydeo avatar Feb 06 '23 08:02 akshaydeo