question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: create switch to persist HTTP method when following a redirect for Invoke-RestMethod or Invoke-WebRequest

See original GitHub issue

Summary of the new feature/enhancement

This request is for a parameter which persists the original HTTP method used in Invoke-RestMethod and Invoke-WebRequest upon redirect. Currently, when the client receives a redirect from the web server, the HTTP client used by said cmdlets reissues the HTTP call but persistently uses HTTP GET, regardless what method was originally used.

This is typical to how browsers operate, and it’s also how cURL operates out of the box, too.

Here is an example:

Invoke-RestMethod -Uri "http://test.acook.io" -Method POST

The web server will redirect the request to https:// and process index.php which just prints out $_SERVER['REQUEST_METHOD'] (link)

Proposed technical implementation details (optional)

A parameter that instructions the cmdlets to persist the originally intended HTTP method through redirects would be useful in scenarios where the web server issues a 30x redirect of http:// to https://.

cURL offers this parameter idea, but for just POST methods, via --post301, --post302 and --post303.

Ideally, this request is to have a switch which persists all types of HTTP methods through redirects via said cmdlets.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
iSazonovcommented, Jan 9, 2021

@codaamok Thanks! Now I see you want a flexibility if a server sends 301 or 302 (I am not sure about 303) wrong status instead of 307 one. I agree it could be useful and I agree to mentor implementation but we need more detail proposal (one parameter? some?) and more feedback.

0reactions
msftbot[bot]commented, Mar 14, 2023

🎉This issue was addressed in #18894, which has now been successfully released as v7.4.0-preview.2.🎉

Handy links:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with REST APIs and PowerShell's Invoke- ...
In the PowerShell world, that client is the Invoke-RestMethod cmdlet. This cmdlet sends HTTP requests using various HTTP methods to REST API ...
Read more >
Powershell v3 Invoke-WebRequest HTTPS error
Using Powershell v3's Invoke-WebRequest and Invoke-RestMethod I have succesfully used the POST method to post a json file to a https website.
Read more >
Invoke-RestMethod - PowerShell
The Invoke-RestMethod cmdlet sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that return richly structured data.
Read more >
PowerShell Core Web Cmdlets in Depth (Part 3)
A change in User-Agent headers means that web servers may potentially serve different content to Invoke-RestMethod and Invoke-WebRequest. You ...
Read more >
Invoke-WebRequest or Invoke-RestMethod?
The Invoke-WebRequest cmdlet sends HTTP, HTTPS, FTP, and FILE requests to a web page or web service. It parses the response and returns ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found