|
HYPERTEXT TRANSFER PROTOCOL Once you look under the hood, there is no magic to HTTP. HTTP stands for Hypertext Transfer Protocol. The protocol, designed by Tim Berners-Lee as early as 1989, is really rather simple. In a nutshell, one application hosts data and "listens" for connections on TCP port 80. (Think of a "port" like a telephone number extension.) Another application then opens a connection to the host on the same port and initiates a dialog. The dialog is simply a request for data (by the client) and response by the host (server). In many ways, the protocol is much simplier than FTP or SMTP. Both of these protocols require there to be a true dialog between client and server. The current implementation of HTTP only requires one request and one response. |
CONNECTING |
One of the best ways to learn about the protocol itself is through the use of your telnet application. All you have to do is telnet on port 80 to a known HTTP server and initiate a request. For example, try telneting to Netscape at home.netscape.com on port 80. Once connected, simply press your return key twice and see what happens. You should get something like this: HTTP/1.0 400 Bad Request Server: Netscape-Enterprise/2.0b4 Your browser sent a message this server could not understand.Here the server replied with an error, specifically error 400. This is correct because you did not send a valid request. At the very least, a WWW browser should specify a "method" and a document in a request. The simplest method is GET and the simplest document is "/". (By the way, method names are case-sensitive.) |
SIMPLEST |
Armed with this newly found information, telnet to www.apple.com on port 80 and when the connection opens enter "GET /" and two carriage returns. This time you should see a whole lot of HTML being sent back to you. This HTML is what your WWW browser would interpret and render on your screen. |
QUALIFYING REQUESTS |
If you specify a version of HTTP in your request, then the responses from servers are more complete and sometimes quite interesting. For example, telnet to www.microsoft.com on port 80 and request "GET / HTTP/1.0". If Microsoft has not changed its page, then new information, called the header, will be displayed before the HTML: HTTP/1.0 302 Object moved Server: Microsoft-IIS/3.0 Date: Tue, 28 Jan 1997 04:03:55 GMT Location: http://msid.msn.com/mps_id_sharing/redirect.asp? www.microsoft.com/default.asp Connection: Keep-Alive Content-Length: 199 Content-type: text/html Set-Cookie: MC1=ID=45e7b538788b11d0a7550000f8485726; expires=Wed, 15-Sep-1999 19:00:00 GMT; domain=.microsoft.com; path=/ Cache-control: private <head><title>Object moved</title> </head><body><h1>Object Moved</h1> This object may be found <a HREF="http://msid.msn.com/mps_id_sharing/redirect.asp? www.microsoft.com/default.asp">here</a>.</body> This header information outlines various information about the reply being returned such as what server is being used, the date, and the length of the data being sent. The most important information is the Content-type. This piece of information tells your browser the MIME type of the data being returned. This information is critical. Otherwise, your browser would not know how to interpret the returned data. |
THE POINT |
The point of this demonstration is two-fold. First, it is a demonstration of the client/server model of computing. One application connects to another application and makes some sort of request. The second application processes the request and returns some sort of results. Second, the demonstrations illustrate the specific sort of dialog that takes place between an HTTP client and server. These examples have not been exhaustive. There are quite a number of other values the client can send in a request, and there are quite a number of other values a server can send in a response. Keep in mind, one of the most important pieces of information being returned by the server is the Content-type. This information is sometimes called the "magic line" and specifies the MIME type of information being returned. It will also be necessary in any CGI scripting you may do. |
Version: 1.5
Last updated: 2004/12/23. See the release notes.
Author: Eric Lease Morgan (eric_morgan@infomotions.com)
URL: http://infomotions.com/musings/waves/