Tip:
Highlight text to annotate it
X
Let's talk a little bit about the difference between GET and POST.
We've already seen one of the differences, and that's
GET parameters are included in the URL
and POST parameters are included in the body.
Another difference is that GET requests
are often used for fetching documents
and GET parameters are usually used to describe
which document we're looking for
or maybe what page we're on
or things of that nature--
basically, things that are describing what we're getting;
where POST parameters are often used for updating data--
for actually making changes to the Server
or to the data held on the Server.
Another difference is that GET parameters--
because they are in the URL--
have a maximum URL length,
or they're affected by the maximum URL length
because you can only encode so many parameters.
For example, I think Internet Explorer
allows 2000 characters in the URL,
or something like that, which can be quite limiting.
POSTs, by default, have no maximum length.
Now, the Server can be configured--and most are--
to have a maximum length, but it's usually substantially longer than 2000 characters.
It's probably a few megabytes.
Another difference is that GET parameters
are generally okay to cache.
And when you make a GET request--a simple request for a URL--
there's a good chance that it's been cached.
There are a lot of machines between
you and the Server--
or often there are--
and it saves a lot of effort
if we know the document hasn't changed
to--you know--cache it along the way
so you don't have to request it new every time.
POST parameters are almost never cached.
That's because you're probably updating data on the Server.
And so the industry standard is: don't cache POST requests.
One more difference is that GET requests--
because they're okay to cache
and because you're usually describing
which document you want--
they shouldn't change the Server.
You should be able to make the same GET request over and over,
and the Server shouldn't change.
POST requests, on the other hand, are okay to change the Server.
That's what they're generally used for,
is requests that update the Server.
That's why they're not cached; there's no max length,
and that's the whole story.
So in short, GET requests should be
simple requests for fetching a document.
And GET parameters should be used to describe
what document or what page you're looking for.
And POST parameters are used for making updates to the Server.
And POST requests generally are destructive in nature.
Now, if you don't follow these rules,
you can get into a little trouble.