From what I can gather, there are three categories:
- Never use
GET
and usePOST
- Never use
POST
and useGET
- It doesn't matter which one you use.
Am I correct in assuming those three cases? If so, what are some examples from each case?
From what I can gather, there are three categories:
GET
and use POST
POST
and use GET
Am I correct in assuming those three cases? If so, what are some examples from each case?
Well one major thing is anything you submit over
GET
is going to be exposed via the URL. Secondly as Ceejayoz says, there is a limit on characters for a URL.HTTP Post data doesn't have a specified limit on the amount of data, where as different browsers have different limits for GET's. The RFC 2068 states:
Specifically you should the right HTTP constructs for what they're used for. HTTP GET's shouldn't have side-effects and can be safely refreshed and stored by HTTP Proxies, etc.
HTTP POST's are used when you want to submit data against a url resource.
A typical example for using HTTP GET is on a Search, i.e. Search?Query=my+query A typical example for using a HTTP POST is submitting feedback to an online form.
Because GETs are purely URLs, they can be cached by the web browser and may be better used for things like consistently generated images. (Set an Expiry time)
One example from the gravatar page: http://www.gravatar.com/avatar/4c3be63a4c2f539b013787725dfce802?d=monsterid
GET may yeild marginally better performance, some webservers write POST contents to a temporary file before invoking the handler.
Another thing to consider is the size limit. GETs are capped by the size of the URL, 1024 bytes by the standard, though browsers may support more.
Transferring more data than that should use a POST to get better browser compatibility.
Even less than that limit is a problem, as another poster wrote, anything in the URL could end up in other parts of the brower's UI, like history.