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.

POST request magically transformed to GET request when POST endpoint is redirected

See original GitHub issue

My steps:

  1. Do axios.post(...) to http://example.com/api/post_endpoint
  2. server responds 301 with http*s*://example.com/api/post_endpoint location
  3. axios sends GET(!) request after redirection

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
makccommented, Oct 12, 2019

you have been warned: Screen Shot 2019-10-12 at 2 21 06

0reactions
RubenVerborghcommented, Nov 8, 2019

Note that @makc above cites the obsolete version of the HTTP 1.1 spec, RFC2616. The paragraph right before the highlighted one states that the user agent MUST NOT automatically redirect unless confirmed by the user, which is thus what libraries are obliged to follow for HTTP 1.1 compatibility.

The latest version, RFC7231, states that:

Automatic redirection needs to done with care for methods not known to be safe, as defined in Section 4.2.1, since the user might not wish to redirect an unsafe request.

https://tools.ietf.org/html/rfc7231#section-6.4

For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead.

https://tools.ietf.org/html/rfc7231#section-6.4.2

That spec text is cited in the source code referred to above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My request is redirected to a GET request - Postman
To do this, open the Settings tab of your request and toggle off the Automatically follow redirects option. Force your request to follow...
Read more >
Why doesn't HTTP have POST redirect?
In HTTP 1.1, there actually is a status code (307) which indicates that the request should be repeated using the same method and...
Read more >
transform Post request using the Post-Redirect-Get pattern in ...
While debugging, using this code it comes into the POST request and redirect to the form but it doesn't enter in the GET...
Read more >
How to retrieve custom headers, query and URI parameters ...
In the tutorial below, we are going to highlight how to retrieve custom headers, queries, and URI parameters from your HTTP request using...
Read more >
Requestly - Lightweight Proxy to Intercept & Modify HTTP(s ...
Requestly allows you to Intercept & Modify network requests. Main features include Mocking APIs Response, Modifying headers, Setting up redirects, ...
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