Java Reference
In-Depth Information
CHAPTER 6
HTTP
The Hypertext Transfer Protocol (HTTP) is a standard that defines how a web client
talks to a server and how data is transferred from the server back to the client. Although
HTTP is usually thought of as a means of transferring HTML files and the pictures
embedded in them, HTTP is data format agnostic. It can be used to transfer TIFF pic‐
tures, Microsoft Word documents, Windows .exe files, or anything else that can be
represented in bytes. To write programs that use HTTP, you'll need to understand HTTP
at a deeper level than the average web page designer. This chapter goes behind the scenes
to show you what actually happens when you type http://www.google.com into the
browser's address bar and press Return.
The Protocol
HTTP is the standard protocol for communication between web browsers and web
servers. HTTP specifies how a client and server establish a connection, how the client
requests data from the server, how the server responds to that request, and finally, how
the connection is closed. HTTP connections use the TCP/IP protocol for data trans‐
fer. For each request from client to server, there is a sequence of four steps:
1. The client opens a TCP connection to the server on port 80, by default; other ports
may be specified in the URL.
2. The client sends a message to the server requesting the resource at a specified path.
The request includes a header, and optionally (depending on the nature of the
request) a blank line followed by data for the request.
3. The server sends a response to the client. The response begins with a response code,
followed by a header full of metadata, a blank line, and the requested document or
an error message.
4. The server closes the connection.
 
Search WWH ::




Custom Search