Whenever a hypertext link is followed or a URL is typed into the
location box of a window, then a GET request is made. However, when a button on
a form is clicked, there is a choice of request types: GET or POST. The POST request
is identical to a GET request, except for the location of the data from the form.
Format of GET Requests
A GET request sends the data from the form via the URL. Until now, every form
has used this method to send data to the server. Below is an example of a GET
request from the edit page from Chapter Three.
GET /?hobby=hiking&confi rmButton=Confi rm HTTP/1.1 Host: tim.cs.fi u.edu:9000 User-Agent: Mozilla/5.0 (Windows; U; ... Accept: image/png,image/jpeg,image/gif,text/css,*/* Accept-Language: en,es;q=0.8,fr;q=0.5,en-us;q=0.3 Accept-Encoding: gzip,defl ate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8085/book/ch5/request_get.jsp
Many request headers provide information about the browser that made the
request. The data from the form has been placed in the URL in the fi rst line of the
request.
Format of POST Requests
A POST request sends the data from the form as part of the request. When POST is used,
the data will not appear in the URL, but will be attached to the end of the request.
POST / HTTP/1.1 Host: tim.cs.fi u.edu:9000 User-Agent: Mozilla/5.0 (Windows; U; ... Accept: image/png,image/jpeg,image/gif,text/css,*/* Accept-Language: en,es;q=0.8,fr;q=0.5,en-us;q=0.3 Accept-Encoding: gzip,defl ate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8085/book/ch5/request_post.jsp Content-Type: application/x-www-form-urlencoded Content-Length: 34 hobby=hiking&confirmButton=Confirm
The headers are mostly the same as for a GET request, e xcept there are two addi-
tional ones: Content-Type and Content-Length. These extra headers indicate the
type and amount of additional content that follows the headers. The data from the
form is formatted the same way as in a GET request. The only difference is that
the data follows the request headers, after a blank line.
What does the word post mean? It means to send, but it also means after. That
is a precise defi nition of a POST request: it posts the data, post the request.