An Introduction to the HTTP protocol
by K. Yue, copyright 2000
Revised: September 17, 2000
HTTP connection
- A HTTP connection is composed of four steps:
- The client opens the connection by contacting the server at the URL
address
- The client sends a request to the server with the appropriate URL address.
- The server sends a response to the client.
- The connection is closed.
- There is only one transaction per connection.
- The HTTP protocol is stateless. The server does not store any information
of the clients.
- To obtain state information from the client, the following methods may be
employed:
- Insert hidden fields of the FORM element can be used.
- Use client side cookies.
Client Requests
- The client request is composed of the following parts in order:
- A request header containing request header fields.
- A method field indicating the method, the identifier of the resource
and the version of HTTP used.
- Accept fields indicating the data types (MIME [Multipurpose Internet
Mail Extension] content-type) he client may accept. Note that */*
means everything is acceptable to the client.
- Other fields such as Referrer (come from which URL), If-Modified-Since
(whether to use cached copy), User-Agent (information about client).
- A blank line (CRLF) indicating the end of the request header.
- The message body (used mainly by the method POST).
- The three most commonly used HTTP methods are:
- GET: To retrieve the URL with user data in the query string of the URL.
Used in:
- ISINDEX: deprecated.
- ISMAP active imagemap.
- FORM with the method GET.
- POST: To retrieve the URL with user data in the message body of the
request. Used in FORM with the method POST.
- HEAD Retrieve the header only from the URL.
Examples:
GET /cgi-bin/formex1?name=Bun+Yue&topic=fish
User-Agent: Mozilla/1.1N (X11; I; IRIX 5.3 IP22)
Accept text/plain
Accept application/html
...
Accept */*
Note that there is a blank line after the last accept field.
POST /cgi-bin/formex2
User-Agent: Mozilla/1.1N (X11; I; IRIX 5.3 IP22)
Accept text/plain
Accept application/html
...
Accept */*
name=Bun+Yue&topic=fish
Server Responses
- The server responses are similar in having three parts:
- A response header with several response fields.
- The first line is the status line indicating the version, the status
code and the explanation.
- Other information about the server and the message such as Date,
MIME-version, Server name and version, content-length (of the data
portion), content type, last-modified, etc.
- A blank line indicating the end of the header.
- The response body which is the html content (such as the content of
a html file).
Example:
HTTP/1.0 200 OK
Date: Fri, 04 Oct 1996 18:05:04 GMT
Server: NCSA/1.4.2
MIME-version: 1.0
Content-type: text/html
Last-modified: Tue, 01 Oct, 1996 12:02:03 GMT
Content-Length: 3109
<HTML>
<HEAD>
<TITLE> Dr. Kwok-Bun Yue Home Page </TITLE>
...
HTTP Status Code
- The HTTP status code has this general meaning:
- 200-299 Successful transaction.
- 300-399 Redirection: to another location or URL has not changed since
last request.
- 400-599 Errors.
- The error messages are:
Code |
Meaning |
400 |
Wrong request syntax. |
401 |
Authorization required. A list of allowed authorization scheme
will also be sent. |
402 |
No Chargeto field on the request for a paid service. |
403 |
Forbidden resource |
404 |
The server cannot find the URL requested. |
405 |
Accessing the resource using a method not allowed. |
406 |
Resource type incompatible with the client. |
410 |
Resource no longer available and no forwarding information
exist. |
500 |
The server has encountered an internal error and cannot continue
with the request. |
501 |
The server does not support the method of a legal
request. |
502 |
Secondary server does not return a valid response. |
503 |
The service is unavailable, because the server is too busy.
|
504 |
Secondary server takes too long to respond. |