The HTTP request

4.2.1 The HTTP request

The simplest HTTP request is as follows:

GET / <enter><enter>

Tip: On some servers, it is necessary to specify the DNS name of the server in the GET request.

4.2 HTTP 89

This request will instruct the server to return the default Web page; how- ever, HTTP requests are generally more complex, such as the following:

GET / HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,

application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*

Accept-Language: en-gb Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT

5.1; .NET CLR 1.0.3705) Host: 127.0.0.1:90 Connection: Keep-Alive

This tells the server several things about the client, such as the type of browser and what sort of data the browser can render.

Table 4.1 shows a complete list of standard HTTP request headers are as follows:

Table 4.1 Standard HTTP request headers .

HTTP header

Meaning

Accept Used to specify which media (MIME) types are acceptable for the response. The type */* indicates

all media types and type/* indicates all subtypes of that type. In the example above, application/ msword indicates that the browser can display Word documents.

Accept-Charset Used to specify which character sets are acceptable in the response. In the case where a client issues Accept-Charset: iso-8859-5 , the server should be aware that the client cannot render Japanese (Unicode) characters.

Accept-Encoding Used to specify if the client can handle compressed data. In the above example, the browser is capable of interpreting GZIP compressed data.

Accept-Language Used to indicate the language preference of the user. This can be used to estimate the geographic location of a client; en-gb in the above example may indicate that the client is from the United Kingdom.

Chapter 4

90 4.2 HTTP

Table 4.1 Standard HTTP request headers (continued).

HTTP header

Meaning

Authorization Used to provide authentication between clients and servers. Refer to RFC 2617 or Chapter 9 for more details.

Host Host indicates the intended server IP address as typed in at the client. This could differ from the actual destination IP address if the request were to go via a proxy. The host address 127.0.0.1:90 in the above example indicates that the client was on the same computer as the server, which was running on port 90.

If-Modified-Since Indicates that the page is not to be returned if it has not been changed since a certain date. This permits a caching mechanism to work effectively. An example is If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT .

Proxy-Authorization This provides for authentication between clients and proxies. Refer to RFC 2617 or Chapter 9 for more details.

Range This provides for a mechanism to retrieve a section of a Web page by specifying which ranges of bytes the server should return; this may not be implemented on all servers. An example is bytes=500- 600,601-999 .

Referer This indicates the last page the client had visited before going to this specific URL. An example is Referer: http://www.w3.org/index.html. (The misspelling of “referrer” is not a typing mistake!)

TE Transfer encoding (TE) indicates which extension transfer encoding it can accept in the response and if it can accept trailer fields in a chunked transfer encoding.

User-Agent Indicates the type of device the client is running from. In the above example, the browser was Internet Explorer 6.

Content-Type Used in POST requests. It indicates the MIME type of the posted data, which is usually application/x-

www-form-urlencoded . Content-Length

Used in POST requests. It indicates the length of the data immediately following the double line.

4.2 HTTP 91

Note: Device-specific HTTP request headers are prefixed with “x-”. GET and POST are the most common HTTP commands. There are oth-

ers, such as HEAD , OPTIONS , PUT , DELETE , and TRACE , and interested readers can refer to RFC 2616 for information on these HTTP commands.

Web developers may be familiar with GET and POST from the HTML form tag, which takes the form:

<form name="myForm" action="someDynamicPage" method="POST">

The difference from a user’s point of view is that form parameters do not appear in the URL bar of the browser when submitting this form. These parameters are contained in the region immediately following the double- line feed. A POST request resembles the following:

POST / HTTP/1.1 Content-Type: application/x-www-form-urlencoded Content-Length: 17

myField=some+text