Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

The Structure of an HTTP Request

The first line of an HTTP request has three space-separated components:

<methods> <request-URI> 
   <HTTP-version>

<method> specifies the type of the request as defined in Table 3.1. <request-URI> can be a full URI, but is typically the path component (such as / or /index.html). <HTTP-version> is the version of HTTP used. This component can only take the values HTTP/1.0 and HTTP/1.1.

The defined request methods are shown in Table 3.1 (the method request names are case sensitive).

Table 3.1 Common HTTP Request Types

Request

Description

GET

Requests a page from the server. This is the normal request used when browsing Web pages.

HEAD

Like GET, but only returns the response header information, and not the page itself. This can be used to obtain information about a page, such as when it was last modified.

POST

This request is used to pass information to the server. Its most common use is with HTML forms where the form data is too long to encode in a GET request (see the later section "Passing Request Parameters").

PUT

Used to put a new Web page on a server. This request is not normally used because of the security implications of allowing a client to change a Web page.

DELETE

Used to delete a Web page from the server. This request is not normally used because of the security implications of permitting a client to change a Web page.

CONNECT

Intended for use with proxy servers and not applicable to servlets and JSPs.

OPTIONS

Intended for use with the Web server itself and not applicable to servlets and JSPs.

TRACE

This is used to request that the server send back the request header to the client in the body of the response, and to check that a connection can be made to the server. The <request-URI> is set to * in this message type.


A typical GET or POST request issued by a Web browser will include header fields containing supplementary information that can be accessed by a servlet. The following is a sample GET request issued to http://www.samspublishing.com by the Netscape 6.2 browser. There might be minor differences in the header fields if the request is issued from a different browser:

GET / HTTP/1.1
Host: http://www.samspublishing.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:0.9.4)
 Gecko/20011128 Netscape6/6.2.1
Accept: text/xml, application/xml, application/xhtml+xml,
 text/html;q=0.9, image/png, image/jpeg, image/gif;q=0.2,
 text/plain;q=0.8, text/css, */*;q=0.1
Accept-Language: en-gb
Accept-Encoding: gzip, deflate, compress;q=0.9
Keep-Alive: 300
Connection: keep-alive

Without going into too much detail, you can see that each header line consists of a field name that is not case sensitive, a colon, and an arbitrary string value. The popular browsers commonly pass the following headers:

Header

Description

Host

Defines the hostname used in the request URL.

User-Agent

Defines the client browser version.

Accept

Defines a list of response body types that the client will accept. The server should not return a response whose MIME type is not in this list.

Connection

Used for connection persistence as described in the later section "Persistent Connections."


  • + Share This
  • 🔖 Save To Your Account