1. Introduction
The Hyper Text Transfer Protocol (HTTP) is the client-server network protocol that has been in use by the World-Wide Web since 1990. Whenever you surf the web, your browser will be sending HTTP request messages for HTML pages, images, scripts and styles sheets. Web servers handle these requests by returning response messages that contain the requested resource.
1.1 HTTP Request Message
The HTTP request message has a simple text based structure. For example, here is the the request message sent by Internet Explorer (IE) for this web page:
GET /httpgallery/introduction/ HTTP/1.1
Accept: */*
Accept-Language: en-gb
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: www.httpwatch.com
Connection: Keep-Alive
The first line of the message, known as the request line, contains:
- The HTTP method. (See 6. HTTP Methods for more information)
- The relative URL of the resource or a full URL if you are using an HTTP proxy
- The version of HTTP that is being used. Most modern HTTP clients and servers will use HTTP version 1.1 as defined in RFC 2616.
The rest of the message consists of a set of name/value pairs, known as headers (See 2. HTTP Headers). HTTP clients use header values to control how the request is processed by the server. For example, the Accept-Encoding header indicates that the browser can handle content compressed using the gzip or deflate algorithms (see 8. HTTP Compression).
1.2 HTTP Response Message
The web server's response message has a similar structure, but is followed by the contents of the HTML page:
HTTP/1.1 200 OK
Server: Microsoft-IIS/8.0
Date: Mon, 04 Jan 2015 12:04:43 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Cache-Control: no-cache, no-store
Expires: -1
Content-Type: text/html; charset=utf-8
Content-Length: 14990
<!DOCTYPE html> <html>...
The first line, or status line, returns a status code from the server that indicates whether the request was successful (see 3. Status codes and errors). The value 200 is returned if the request was processed correctly and content is being returned to the client.
The next eight lines of text contain header values that describe the data and the way in which it is being returned to the client. For example, Content-Type has the value text/html because the page is in HTML format. The response headers are terminated with a double CRLF (carriage return, line feed) and are followed by the contents of the requested resource.
Images are not directly embedded into web pages. Instead, they are specified as separate resources using HTML <img> tags:
<img src="images/logo.gif" width="50" height="50">
Whenever the browser encounters an <img> tag, it checks to see if it has a valid copy of the image either loaded in memory or saved in its cache. If no suitable match is found, it sends out another HTTP request to retrieve it. This means that a web page will usually generate multiple HTTP requests; one for the HTML page and one for each of the images.
Example 1
Clicking the Refresh button will redisplay this web page by sending HTTP requests to download the HTML of the page and its associated styles sheets and images.
Using HttpWatch with Example 1
- Open HttpWatch by right clicking on the web page and selecting HttpWatch from the context menu
- Click on Record to start logging requests in HttpWatch
- Click on the Refresh HTTP request button above
The HttpWatch window will display about 8 entries. The first is for the page itself; the others are for the style sheets and images used by this page. Select the first entry and then click on the Stream tab to see the HTTP request and response messages described above.