Knowledge Base
Site Map

HTTP Message Format

There are two types of HTTP messages, request messages, request messages and response messages. An HTTP request message can have many lines or as few as one line. The first line of an HTTP request is called the request line; the subsequent lines are called the header lines. The request line has three fields: the method field, the URL field, and the HTTP version field. The method field can take on several different values, including GET, POST, and HEAD. The majority of HTTP request messages use the GET method.

A typical HTTP request message may look like this:

GET / somedir/page.html HTTP/1.1

HOST: www.someschool.edu

Connection: close

User-agent: Mozilla/4.0

Accept-Language: fr

The GET method is used when the browser request an object, with the requested object identified in the URL field. The HOST header line specifies the host on which the object resides and is required by Web proxy cache. The Connection: close header line, the browser is telling the server it doesn't want to bother with persistent connections; it wants the server to close the connection after sending the requested object. The USER-agent : header line specifies the user agent or browser type that is making the request to the server. This header line is useful because the server can actually send different versions of the same object to different types of user agents. The Accept-language : header indicates that the user prefers
to receive a French version of the object, if such an object exists on the server; otherwise
the server should send its default version.

After the header lines there is an “entity body” which is empty with the GET method, but is
used with the POST method. An HTTP client often uses the POST method when the user fills
out a form. With a POST message, the user is still requesting a Web page from the server, but
the specific contents of the page depend on what the user entered into the form fields. If the
value of the method field is POST, then the entity body contains what the use entered into
the form fields. A requested generated with a form does not have to use the POST method.
HTML forms often use the GET method and include the inputted data in the requested URL.

The HEAD method is similar to the GET method, it responds with and HTTP message but it
leaves out the requested object. In addition to the methods mentioned, the HTTP/1.1
specification allows for several additional methods including PUT and DELETE. The PUT
method is often used in conjunction with Web publishing tools. It allows a user to upload an
object to a specific path on a specific Web server. The PUT method is also used by
applications that need to upload objects to Web servers. The DELETE method allows a user,
or an application, to delete an object on a Web server.


The below HTTP response message could be the response to the example request message mentioned prior.

HTTP/1.1 200 OK

Connection: close

Date: Thu, 03 Jul 2003 12:00:15 GMT

Server: Apache/1.3.0 (Unix)

Last-Modified: Sun, 5 May 2003 09:23:24 GMT

Content-Length: 6821

Content-Type: text/html

(data data data data data …)


This response message has three sections: the initial status line, six header lines, and
the entity body. The entity body is the meat of the message—it contains the requested
object itself (represented by data data data data…). The status line has three fields: the
protocol version field, a status code, and a corresponding status message. Looking at the
header lines, we see the server uses the Connection: close message. The Date: header line
indicates the time and date when the HTTP response was created and sent by the server.
This is not the time when the object was created or last modified, it is the time when the
server retrieves the object from its file system, inserts the object into the response message
and send the response message. The Server: header line indicates the message was generated
by and Apache Web server; it is analogous to the User-agent: header line in the HTTP
request message. The Last-Modified: header is critical for object caching, both in local client
and in network cache servers. The Content-Length: header line indicates the object in the
entity body is HTML text.

The status code and associated phrase indicate the result of the response. A browser will
generate header lines as a function of the browser type and version, the user browser
currently has a cached, but possibly out of date version of the object. Web servers behave
similarly: There are different products, versions, and configurations, all of which influence
which header lines are included in response messages.