The HTTP Request
The browser sends the HTTP request to the web server and it contains the following:
The Request Line
The first line of every HTTP request is the request line, which contains three pieces of information:
- An HTTP command known as a method
- The path from the server to the resource that the client is requesting
- The version number of HTTP.
So, an example request line might look like this:
GET /testpage.htm HTTP/1.1
The method is used to tell the server how to handle the request. Here are three of the most common methods that might appear in this field:

There are a number of other methods supported by HTTP - including PUT, DELETE, TRACE, CONNECT, and OPTIONS. As a rule, you'll find that these are less common; they are therefore beyond the scope of this discussion.If you want to know more about these, take a look at RFC 2068, which you can find at http://www.rfc.net.
The HTTP Header
The next bit of information sent is the HTTP header. This contains details of what document types the client will accept back from the server, like the type of browser that has requested the page, the date, and general configuration information. The HTTP request's header contains information that falls into three different categories:
- General: contains information about either the client or server, but not specific to one or the other
- Entity: contains information about the data being sent between the client and server
- Request: contains information about the client configuration and different types of acceptable documents
An example HTTP header might look like this:
Accept: */*
Accept-Language: en-us
Connection: Keep-Alive
Host: www.wrox.com
Referer: http://webdev.wrox.co.uk/books/SampleList.php?bookcode=3730
User-Agent: Mozilla (X11; I; Linux 2.0.32 i586)
As you can see, the HTTP header is composed of a number of lines; each line contains the description of a piece of HTTP header information, and its value.
There are many different lines that can comprise a HTTP header, and most of them are optional, so HTTP has to indicate when it has finished transmitting the header information. To do this, a blank line is used. In HTTP 1.1, a request must comprise of at least a request line and a HOST header.
The HTTP Body
If the POST method was used in the HTTP request line, then the HTTP request body will contain any data that is being sent to the server - for example, data that the user typed into an HTML form (we'll see examples of this later in the book). Otherwise, the HTTP request body will be empty.
The HTTP Response
The HTTP response is sent by the server back to the client browser, and contains the following.
The Response Line
The response line contains only two bits of information:
- The HTTP version number
- An HTTP request code that reports the success or failure of the request
An example response line might look like this:
HTTP/1.1 200 OK
This example returns the HTTP status code 200, which represents the message "OK". This denotes the success of the request, and that the response contains the required page or data from the server. You may recall that we mentioned the status code 404 a few pages ago - if the response line contains a 404 then the web server failed to find the requested resource. Error code values are three-digit numbers, where the first digit indicates the class of the response. There are five classes of response: