Java Reference
In-Depth Information
The above URL is not represented exactly in URL form in the request header. The
Host ” header line in the header names the web server that contains the file. The request
shows the remainder of the URL, which in this case is /1/1/typical.php . Finally, the
third thing that the first line provides is the version of the HTTP protocol being used. As of
the writing of this topic there are only two versions currently in widespread use:
• HTTP/1.1
• HTTP/1.0
This topic only deals with HTTP 1.1. Because this topic is about writing programs to con-
nect to web servers, it will be assumed that HTTP 1.1 is being used, which is what Java uses
when the Java HTTP classes are used.
The lines after the first line make up the actual HTTP headers. Their format is colon
delimited. The header name is to the left of the colon and the header value is to the right. It
is valid to have two of the same header name in the same request.
The headers give a variety of information. Examining the headers shows type of browser
as well as the operating system and other information. In the headers listed above, in List-
ing 1.3, the Safari browser was being used on the Macintosh platform. Safari is the built in
browser for the Macintosh platform.
The headers finally terminate with a blank line. If the request had been a POST , any
posted data would follow the blank line. Even when there is no posted data, as is the case with
a GET , the blank line is still required.
A web server should respond to every HTTP request from a web browser. The web
server's response is discussed in the next section.
HTTP Response Headers
When the web server responds to a HTTP request, HTTP response header lines are
sent. The HTTP response headers look very similar to the HTTP request headers. Listing 1.4
shows the contents of typical HTTP response headers.
Listing 1.4: Typical Response Headers
HTTP/1.1 200 OK
Date: Sun, 02 Jul 2006 22:28:58 GMT
Server: Apache/2.0.40 (Red Hat Linux)
Last-Modified: Sat, 29 Jan 2005 04:13:19 GMT
ETag: "824319-509-c6d5c0"
Accept-Ranges: bytes
Content-Length: 1289
Connection: close
Content-Type: text/html
Search WWH ::




Custom Search