When to use form POST vs GET?

I read a post today from Mark Kruger where he was warning against the possible side effects when using GET as a form submit method.

I think I (unintentionally) offended Mark with my comment where I asked why would anyone EVER use GET? because I pretty much always use POST so was wondering why you would use GET.

In my search for answers I asked Mark Lynch who seems to always have the answer to my questions :)

So in summary (from Michael Schwarz);

POST

1. By default no proxy server or web browser is caching this data, you will always get the real data from you web server.
2. The length of data you can send to the web server is only restricted by the web server itself, but there is no real restriction.
3. Character encoding can be done easily using application/x-www-form-urlencoded.

GET

1. Running a http request with GET can be cached on your web browser or a configured proxy server.
2. To get the live data from you web server you have to modify the url that is used in your XHR invoke, simply by using a counter or new Date().getTime() which will generate a unique url.
3. Maximum URL length is 2,083 characters in Internet Explorer (see MaxClientRequestBuffer: Use POST instead of GET to Send Large Amounts of Data in Request)
4. 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. [RFC 2616 sec 9]
5. Character encoding will reduce the amount of data that can be used because of url encoding entities (i.e. three Japanese characters are converted to this: %26%2312454%3B%26%2312455%3B%26%2312502%3B)

There is also a great article here if you want some further reading on this subject.

For me (at this stage) this really only has an effect when doing Ajax. If I’m purely wanting to retrieve data (just HTML for example) from the server then I’ll use GET, but if I want to do something else with server side effects (such as posting data to be saved to a database) then I’ll use POST.

Phew…you learn something new everyday!

Post a Comment or Leave a Trackback

4 Comments

  1. January 29, 2008 at 3:17 pm | Permalink

    GET also makes CSRF a lot easier

  2. August 1, 2008 at 12:51 pm | Permalink

    Thanks for the post! I was looking for post vs get and This was very informative.

  3. March 31, 2010 at 10:44 am | Permalink

    Great info thanks!

  4. April 19, 2010 at 3:42 pm | Permalink

    Thanks for the info! Very helpful!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*