Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

So why should we use POST instead of GET for posting data? [duplicate]

Tags:

http

post

Possible Duplicates:
How should I choose between GET and POST methods in HTML forms?
When do you use POST and when do you use GET?

Obviously, you should. But apart from doing so to fulfil the HTTP protocol, are there any reasons to do so? Less overhead? Some kind of security thing?

like image 609
cwap Avatar asked Aug 10 '09 10:08

cwap


People also ask

Why POST method is better than GET?

POST request is comparatively more secure because the data is not exposed in the URL bar. Request made through GET method are stored in Browser history. Request made through POST method is not stored in Browser history. GET method request can be saved as bookmark in browser.

Why is POST more secure than GET?

GET is less secure than POST because sent data is part of the URL. POST is a little safer than GET because the parameters are stored neither in the browser history nor in the web server logs.

Why not use GET instead of POST?

As with submitting any form data, you have the option of submitting your data in the form of GET requests, and you will save a few lines of code if you do so. However, there is a downside: some browsers may cache GET requests, whereas POST requests will never be cached.

When should I use GET vs POST?

GET retrieves a representation of the specified resource. POST is for writing data, to be processed to the identified resource. 2. It typically has relevant information in the URL of the request.


2 Answers

because GET must not alter the state of the server by definition.

see RFC2616 9.1.1 Safe Methods:

9.1.1 Safe Methods

Implementors should be aware that the software represents the user in their interactions over the Internet, and should be careful to allow the user to be aware of any actions they might take which may have an unexpected significance to themselves or others.

In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.

If you use GET to alter the state of the server then a search engine bot or some link prefetching extension in a web browser can wreak havoc on your site and (for example) delete all user data just by following links to your site.

like image 197
levinalex Avatar answered Dec 25 '22 16:12

levinalex


There is a nice paper by the W3C about this: URIs, Addressability, and the use of HTTP GET and POST.

1.3 Quick Checklist for Choosing HTTP GET or POST

  • Use GET if:
    • The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup).
  • Use POST if:
    • The interaction is more like an order, or
    • The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service), or
    • The user be held accountable for the results of the interaction
like image 30
Joey Avatar answered Dec 25 '22 15:12

Joey