When to use GET or POST
The HTML 2.0 specification says, in section Form
Submission (and the HTML 4.0 specification repeats this with minor stylistic changes):
–>If the processing of a form is idempotent
(i.e. it has no lasting observable effect on the state of the world), then the form method should be GET. Many database searches have no visible side-effects and make ideal applications of query forms. – –>If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.
How the form data is transmitted?
quotation from the HTML 4.0 specification
–> If the method is “get” – -, the user agent
takes the value of action, appends a ? to it, then appends the form data set, encoded using the application/x-www-form-urlencoded content type. The user agent then traverses the link to this URI. In this scenario, form data are restricted to ASCII codes. –> If the method is “post” –, the user agent conducts an HTTP post transaction using the value of the action attribute and a message created according to the content type specified by the enctype attribute.
Quote from CGI FAQ
Firstly, the the HTTP protocol specifies
differing usages for the two methods. GET requests should always be idempotent on the server. This means that whereas one GET request might (rarely) change some state on the Server, two or more identical requests will have no further effect.
This is a theoretical point which is also good
advice in practice. If a user hits “reload” on his/her browser, an identical request will be sent to the server, potentially resulting in two identical database or guestbook entries, counter increments, etc. Browsers may reload a GET URL automatically, particularly if cacheing is disabled (as is usually the case with CGI output), but will typically prompt the user before re-submitting a POST request. This means you’re far less likely to get inadvertently-repeated entries from POST.
GET is (in theory) the preferred method for
idempotent operations, such as querying a database, though it matters little if you’re using a form. There is a further practical constraint that many systems have built-in limits to the length of a GET request they can handle: when the total size of a request (URL+params) approaches or exceeds 1Kb, you are well-advised to use POST in any case.
I would prefer POST when I don’t want the status to
be change when user resubmits. And GET when it does not matter. |
Oct 15, 2014
What are the differences between Get and post methods in form submitting. give the case where we can use get and we can use post methods?
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment