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.
This chapter covers all the basics of HTTP. For absolutely complete coverage of HTTP and all its surrounding technologies, see HTTP: The Definitive Guide by David Gourley and Brian Totty, with Marjorie Sayer, Sailu Reddy, and Anshu Aggarwal (O’Reilly).
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:
The client contacts the server at a designated port number (by default, 80). It 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 makes use of the
GETmethod to request the document index.html using Version 1.1 of HTTP. HTTP methods are discussed in more detail later in this chapter.
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 ...