Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

HTML 4.0 Sourcebook
(Publisher: John Wiley & Sons, Inc.)
Author(s): Ian S. Graham
ISBN: 0471257249
Publication Date: 04/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Example 15: Using the HEAD Method

In this example, we suppose that the user (or some automated program, such as a robot or spider) wants to access HEAD information about the document referenced in Example 13. The request that would be sent to the server is simply:

HEAD /Tests/file.html HTTP/1.0
User-Agent: HEAD Test Agent
From: name@domain.name.edu

The request does not need accept header fields, since no data are being retrieved. The From field gives the server the electronic mail address of the user making the HEAD request—it is important to give this information if the request comes from an automated program. A typical response (in this case, from an Apache 1.1.1 HTTP server) is:

HTTP/1.0 200 OK
Date: Wed, 09 Oct 1996 23:10:55 GMT
Server: Apache/1.1.1
MIME-version: 1.0
Content-type: text/html
Content-length: 139
Last-modified: Fri, 20 Sep 1996 19:44:28 GMT

This indicates that the document exists (the status code 200 indicates a valid URL) and includes information about the document type and the date it was last modified. If this URL referenced a dynamic resource, such as a program or a parsed HTML document (see Chapter 10), the content-length and last-modified headers would be absent to indicate that the length is unknown a priori and that the document is essentially new every time it is accessed.

If the HEAD request references an HTML document, some servers will parse the document HEAD and extract META element information for inclusion in the response header. This server feature is not widely implemented.

Lessons from Example 15

1.  A HEAD request retrieves only the response header for the indicated URL—the document itself is not retrieved. If the HEAD request targets an HTML document, some servers parse the document HEAD for information to include in the response header. This feature is not widely implemented.

Sending Data to a Server: GET and POST

The HTTP protocol supports several methods for sending data from client to server. The most common are GET and POST, which are used as the interface between HTML FORMs or ISINDEX queries and server-side processing programs. The PUT method, on the other hand, is used to create new resources (such as files) on a server. PUT is described later in this chapter.

Example 16: GET Method with a Query String

This example illustrates a GET method request, but with query information appended to the URL. As discussed in Chapters 2 and 8, query information is appended to the URL following a question mark. This encoding is done automatically by Web browsers when an ISINDEX query or, depending on the mechanisms used, when an HTML FORM is submitted. An example URL is

<http://www.stuff.ca/cgi-bin/srch-example?item1+item2+item3+item4>

which passes four items from an ISINDEX query to the program srch-example.

Figure 9.5 shows the request headers sent by the Internet Explorer 3.0 browser when accessing this URL. This request header is essentially the same as that in Figure 9.3, the only important difference being the query string appended to the locator string. The server’s handling of query strings is described in the next chapter.

Lesson from Example 16

1.  Query data appended to a URL during a GET request to a server are passed as part of the locator string in the HTTP method field of the request header. All other request header fields are the same as those for a standard GET request, as described in Examples 13 and 14.


Figure 9.5 Data sent from the Internet Explorer 3.0 Beta 1 browser to an HTTP server during a GET request that has a query string appended to the URL. Comments are in italics.

GET /cgi-bin/srch-example?item1+item2+item3+item4 HTTP/1.0
Accept: */*
Accept-Language: en
User-Agent: Mozilla/2.0 (compatible; MSIE 3.0B; Windows 95;1024,768)
Host: smaug.middle.earth.ca
   [a blank line, containing only CRLF ]

Example 17: Submitting a FORM Using the GET Method

This example examines how an HTML FORM sends form data to a server when the GET method is used. The example FORM is shown in Figure 9.6. The actual rendering of this form by a Web browser is shown in Figure 9.7.

The FORM element was discussed in detail in Chapter 6. This FORM defines the three variable names: srch, srch_type, and srvr. These have been assigned, by user input, the values srch=dogfish, srch_type=Exact Match, srvr=Canada, and srvr=Sweden. Figure 9.8 shows the data sent by the Netscape Navigator 3 to the server when the FORM is submitted.

As discussed in Chapters 6 and 8, the default method of submitting a FORM sends the data to the server as a collection of encoded name/value pairs. The names and values from each FORM input element are encoded and composed into strings of the form name=value, with ampersand characters (&) separating the composite strings (e.g., name1=value1&name2=value2...). With the GET method, this string is appended to the URL as a query string, separated from the base of the URL by a question mark. When the HTTP server receives these data, it forwards the entire query string to the gateway program form1 referenced by the URL. These details are discussed in Chapter 10.


Figure 9.6 Example HTML FORM that uses the GET method to submit data to a server.

<FORM ACTION="http://smaug.java.utoronto.ca:2021/cgi-bin/form1"
      METHOD=GET>
<p> Search string: <INPUT TYPE="text" NAME="srch" VALUE="dogfish">
<p> Search Type:
  <SELECT NAME="srch_type">
    <OPTION> Insensitive Substring
    <OPTION SELECTED> Exact Match
    <OPTION> Sensitive Substring
    <OPTION> Regular Expression
  </SELECT>
<p> Search databases in:
  <INPUT TYPE="checkbox" NAME="srvr" VALUE="Canada" CHECKED> Canada
  <INPUT TYPE="checkbox" NAME="srvr" VALUE="Russia"  > Russia
  <INPUT TYPE="checkbox" NAME="srvr" VALUE="Sweden" CHECKED> Sweden
  <INPUT TYPE="checkbox" NAME="srvr" VALUE="U.S.A."  > U.S.A.
  <em>(multiple items can be selected.)</em>
<P> <INPUT TYPE="submit"> <INPUT TYPE=reset>.
</FORM>


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.