Chapter 17. HTTP

The Hypertext Transfer Protocol (HTTP) is the language web clients and servers use to communicate with each other. It is essentially the backbone of the World Wide Web. While HTTP is largely the realm of server and client programming, a firm understanding of HTTP is also important for CGI programming. In addition, sometimes HTTP filters back to the users—for example, when server error codes are reported in a browser window.

All HTTP transactions follow the same general format. Each client request and server response has three parts: the request or response line, a header section, and the entity body. The client initiates a transaction as follows:

  1. The client contacts the server at a designated port number (by default, 80). It then sends a document request by specifying an HTTP command called a method, followed by a document address, and an HTTP version number. For example:

    GET /index.html HTTP/1.1

    This uses the GET method to request the document index.html using Version 1.1 of HTTP. HTTP methods are discussed in more detail later in this chapter.

  2. Next, the client sends optional header information to inform the server of its configuration and the document formats it will accept. All header information is given line by line, each with a header name and value. For example, this header information sent by the client indicates its name and version number and specifies several document preferences:

    User-Agent: Mozilla/4.05(WinNT; I) Accept: image/gif, image/x-xbitmap, image/jpeg, ...

Get Webmaster in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.