GET request can be bookmarked and POST can not . Can anybody explain on this?
I am studying the HTTP methods. I read that GET request can be bookmarked and POST request can not be bookmarked. Can anybody explain this with an example?
Thanks
An HTTP POST can be bookmarked, but since a bookmark only consists of the URL, all of the form parameters will be lost. This will often mean that the web server doesn't know what to do with the request, since it was expecting some form parameters.
If you submit a form via a GET request, all of the form parameters go into the URL (after the ?), so a bookmark will contain all of the information needed for the webserver to rebuild the page a second time (except for cookies, perhaps, but a webserver is more likely to handle that gracefully)
A POST cannot be bookmarked. Attempting to bookmark a POST will just result in a GET operation on the URL. There's a very good reason for this, GET requests are supposed to be idempotent - that is, making the same GET request numerous times should result in the same response. POST requests on the other hand are not. Allowing POSTs to be bookmarked could result in you paying for something twice, transferring money out of your bank account again, etc.
It is not that the one or other cannot be bookmarked. It is more that clicking a bookmark will always fire a GET
request! Clicking a plain vanilla link, bookmark, browser nav button, entering browser address bar, etcetera all fires a GET
request. They never fires a POST
request. A POST
request is normally only fired when you submit a HTML <form>
which is set with method="post"
. You can perfectly program software to bookmark a POST
request, but it is not done so due to sensitive reasons.
The special thing here however is that a GET
request is idempotent . In other words, it is guaranteed to give the same result everytime when you invoke it. That is quite simple as all request parameters are just available in the request URL. You can use it to preprocess data prior to display. In Java Servlet world, you normally use doGet()
method for this which preloads some stuff based on the request parameters at end forwards the request to a JSP file for display.
A POST
request however is not idempotent. In other words, it is not guaranteed to give the same result everytime when you invoke it. All request parameters are included in the request body. It is not visible for the enduser and also not visible in the request URL. In other words, you cannot bookmark it. You can use it ro postprocess data after a form submit. In Java Servlet world, you normally use doPost()
method for this which gathers the request parameters and stores it in some database and at end forwards or redirects the request to a JSP file for result/confirmation/display.