Академический Документы
Профессиональный Документы
Культура Документы
by the World Wide Web. HTTP defines how messages are formatted
and transmitted, and what actions Web servers and browsers should
take in response to various commands. For example, when you enter
a URL in your browser, this actually sends an HTTP command to the
Web server directing it to fetch and transmit the requested Web page.
The other main standard that controls how the World Wide Web
works is HTML, which covers how Web pages are formatted and
displayed.
HTTP operates over TCP connections, usually to port 80, though this
can be overridden and another port used. After a successful
connection, the client transmits a request message to the server,
which sends a reply message back. HTTP messages are human-
readable, and an HTTP server can be manually operated with a
command such as telnet server 80.
The simplest HTTP message is "GET url", to which the server replies
by sending the named document. If the document doesn't exist, the
server will probably send an HTML-encoded message stating this. I
say probably, because this simple method offers poor error handling
and has been deprecated in favor of the more elaborate scheme
outlined below.
A complete HTTP 1.0 message begins "GET url HTTP/1.0". The
addition of the third field indicates that full headers are being used.
The client may then send additional header fields, one per line,
terminating the message with a blank link. The server replies in a
similar vein, first with a series of header lines, then a blank line, then
the document proper.
Here a sample HTTP 1.0 exchange:
GET / HTTP/1.0 >
>
< HTTP/1.0 200 OK
< Date: Wed, 18 Sep 1996 20:18:59 GMT
< Server: Apache/1.0.0
< Content-type: text/html
< Content-length: 1579
< Last-modified: Mon, 22 Jul 1996 22:23:34 GMT
<
< HTML document
The use of full headers is preferred for several reasons:
In addition to GET requests, clients can also send HEAD and POST
requests, of which POSTs are the most important. POSTs are used
for HTML forms and other operations that require the client to
transmit a block of data to the server. After sending the header and
the blank line, the client transmits the data. The header must have
included a Content-Length: field, which permits the server to
determine when all the data has been received.
HTTP Properties
A technical definition of the World Wide Web is: all the resources and users
on the Internet that are using the Hypertext Transfer Protocol (HTTP).
http://www.ietf.org/html.charters/http-
charter.html
Requests
A request from a client to a server includes the
following information:
• Request method
• Request header
• Request data
Request Method
A client can request information using a number of
methods. The commonly used methods include the
following:
Request Header
The client can send header fields to the server. Most
are optional. Some commonly used request headers
are shown in Table A.1.
Table A.1 Description
Common request
headers
Request header
Accept The file types the client can
accept.
Authorization Used if the client wants to
authenticate itself with a
server; information such as
the username and password
are included.
User-agent The name and version of the
client software.
Referer The URL of the document
where the user clicked on the
link.
Host The Internet host and port
number of the resource being
requested.
Request Data
If the client has made a POST or PUT request, it can
send data after the request header and a blank line.
If the client sends a GET or HEAD request, there is
no data to send; the client waits for the server's
response.
Responses
The server's response includes the following:
• Status code
• Response header
• Response data
Status Code
When a client makes a request, one item the server
sends back is a status code, which is a three-digit
numeric code. There are four categories of status
codes:
Introducing HTTP
HTTP Communications
HTTP Transactions
Connection
In this phase, the browser attempts to connect with the Web
server. You can observe this happening on most browsers by
watching the status line for a message indicating that it is
connecting to the HTTP server.
Request
You can use your Web browser to get information about the various
HTTP methods at:
http://www.w3.org/hypertext/WWW/Protocols/HTTP/Methods.html
Every time a browser requests a page, it sends the server a
list of the MIME types it can support.
Response
Close
After the server sends the response, either the client, the
server, or both close the connection.
As shown in Figure 7, most HTTP communications are
initiated by a user agent and consist of a request to be
applied to a resource on some origin server. In the simplest
case, this may be accomplished through a single connection
between the user agent and the origin server.
Figure 7 Simple HTTP Communication Transaction
HTTP Request
Client : GET DEFAULT.HTM HTTP/1.0
Accept: text/plain
Accept: image/gif/
Accept: image/x-portable-bitmap
User-Agent: NCSA WinMosaic 1.0
HTTP Response
Server : HTTP/1.0 200 OK
MIME-Version: 1.0
Content-Type: text/html
Date: Thursday, 3-AUG-96 23:37:8 GMT
Content-Length: 1618
<TITLE>PURVEYOR ENCRYPT WEBSERVER</TITLE>
The client can send any one or more of the following header
lines in a HTTP protocol transaction. The list of headers is
terminated by an empty line. Table 5 lists some commonly
used header request fields. Note that the HTTP protocol lists
many more header fields. Refer to the URL
http://www.w3.org/hypertext/WWW/Protocols/ for
additional information.
Table 5 Commonly Used Header Request Fields
Header Description
From In Internet mail format, the name of the
requesting user. The Internet mail address in this
field does not have to correspond to the internet
host that issued the request.
Accept-Encoding: x-zip
Accept- Lists the Language values preferable in the
Language response. A response in an unspecified language
is not illegal.
User-Agent If present gives the software program used by the
original client. This is for statistical purposes and
to trace protocol violations.
Internationalization