Why does the back button not work with HTTP POST?

假如想象 提交于 2019-12-08 07:50:26

问题


What is the reason that we cannot use the browser Back button when we submit a page using HTTP POST? But it is fine with HTTP GET? I have read that the browser tries to prevent multiple POSTS (to avoid multiple updates to server) because it cannot tell the difference between BACK and RELOAD on the browser? How can browser not tell between BACK and RELOAD?


回答1:


Back isn't a special request that goes to the server. Back just navigates to the previous page, same as if you just entered the url in the navigation bar and hit go. It's really the same thing as a reload which is the same as a basic page request from the server's point of view. They're all just GET requests.

When you hit back on a page that used a post, it resends a post rather than a get. Generally browsers have built in protections against that ("Are you sure you want to go back? Browser will resend previously submitted information").

The reason it doesn't reload posts like that is because, like you said, it doesn't want to resend the information used to get that page to the server, because it'll double post something, or double buy something.



来源:https://stackoverflow.com/questions/16091067/why-does-the-back-button-not-work-with-http-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!