Java Reference
In-Depth Information
This is the basic HTTP 1.0 procedure. In HTTP 1.1 and later, multiple requests and
responses can be sent in series over a single TCP connection. That is, steps 2 and 3 can
repeat multiple times in between steps 1 and 4. Furthermore, in HTTP 1.1, requests and
responses can be sent in multiple chunks. This is more scalable.
Each request and response has the same basic form: a header line, an HTTP header
containing metadata, a blank line, and then a message body. A typical client request
looks something like this:
GET /index.html HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:20.0)
Gecko/20100101 Firefox/20.0
Host: en.wikipedia.org
Connection: keep-alive
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
GET requests like this one do not contain a message body, so the request ends with a
blank line.
The first line is called the request line , and includes a method, a path to a resource, and
the version of HTTP. The method specifies the operation being requested. The GET
method asks the server to return a representation of a resource. /index.html is the path
to the resource requested from the server. HTTP/1.1 is the version of the protocol that
the client understands.
Although the request line is all that is required, a client request usually includes other
information as well in a header. Each line takes the following form:
Keyword : Value
Keywords are not case sensitive. Values sometimes are and sometimes aren't. Both key‐
words and values should be ASCII only. If a value is too long, you can add a space or
tab to the beginning of the next line and continue it.
Lines in the header are terminated by a carriage-return linefeed pair.
The first keyword in this example is User-Agent , which lets the server know what
browser is being used and allows it to send files optimized for the particular browser
type. The following line says that the request comes from version 2.4 of the Lynx brows‐
er:
User-Agent: Lynx/2.4 libwww/2.1.4
All but the oldest first-generation browsers also include a Host field specifying the
server's name, which allows web servers to distinguish between different named hosts
served from the same IP address:
Host: www.cafeaulait.org
Search WWH ::




Custom Search