Weird behavior while invoking Rest call using Invoke-RestMethod on Powershell script

54 views Asked by At

I want to pass body(parameters) to Rest-call using Invoke-RestMethod(powershell script) in GET call. but I think it's not supported because of some security reasons(some RFC standards).

But in single session, When I first use POST method and then if I use GET method then it works. but if I directly call get method then it's throwing below error.

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send

So, Is there some information powershell stores after first call ? Also, Is there any way to pass parameters to "GET" Restcall in powershell script ?

I've attached code snippet: this snippet is working.

Invoke-RestMethod 'https://test_url/url_path?param1=par' -Method 'POST' -Headers $headers

Invoke-RestMethod 'https://test_url/url_path?param1=par' -Method 'GET' -Headers $headers  # works

but this throws the error,

Invoke-RestMethod 'https://test_url/url_path?param1=par' -Method 'GET' -Headers $headers #Not works
0

There are 0 answers