Post-Redirect-Get with Internet Explorer

2019-02-16 14:22发布

问题:

I have a web page that implements the post/redirect/get pattern to avoid double posts in a simple CRUD application.

The intended request/response sequence here is:

  1. browser sends data via POST
  2. server modifies the DB, responds with status 302 Moved Temporarily and a Location header
  3. browser follows the redirect via GET
  4. server responds with the updated page

This is how it is supposed to work – and it does, in Chrome for example.

Internet Explorer 9, however, sends step 3 as a POST, too (including the complete set of form data!). Why? What should I do to make it use GET?

I should add that apart from the query string the redirect goes to the same location as the form target.

I've tried:

  • all available of rendering modes (IE7, IE8, IE9, Quirks, Standards, Compat)
  • a full DOCTYPE
  • a relative URL or an absolute one in the Location header
  • HTTP Status 303 (just to see if that makes any difference)

回答1:

The correct status code if you want a GET is 303, although 301 and 302 will also do what you want in common browsers.

If this is not working, something else probably is wrong. An HTTP trace would be helpful for finding what is wrong.



回答2:

I'm not sure but it seems like IE9 doesn't actually sent "POST" after redirect 30x - it just displays it in his internal debugger.



回答3:

I noticed similar behavior. Turns out IE11's internal debugger was reporting a POST but using a third party app (Fiddler) it reported the request as being a GET. If you see a POST in response to a 303/302, double check it with an outside app.