Refreshing a page in a browser yields POST or GET

2019-07-03 16:03发布

I am learning asp.net mvc form processing now and confused with the following:

What happens if we push the refresh button on the browser? It makes a POST or GET request?

标签: post browser get
2条回答
不美不萌又怎样
2楼-- · 2019-07-03 16:31

This is dependant on the last call that was made by the browser to get the current data. Eg:

a) If you submitted a form, performing a POST and then hit refresh, the browser will do another POST.

b) If you just clicked a link that took you to another page, performing a GET, you'll a refresh will perform a get.

If you're just starting out understanding the GET/POST methods, there is a nice pattern that you should understand that will help you not get in situations where data is posted again and again by users who constantly refresh the browser after a POST:

http://en.wikipedia.org/wiki/Post/Redirect/Get

and

An example specifically for asp.net MVC

查看更多
趁早两清
3楼-- · 2019-07-03 16:36

Whatever HTTP method was used to generate the page will be repeated when you hit refresh.

If you're using <% Html.BeginForm(...) %> when the form is submitted, it will create a POST, and if the resulting page is refreshed, it will repeat the POST.

查看更多
登录 后发表回答