<?xml version="1.0" encoding="ISO-8859-1"?>

<document>

  <properties>
    <title>Get Method</title>
    <author email="adrian@ephox.com">Adrian Sutton</author>
    <revision>$Id$</revision>
  </properties>

  <body>

    <section name="Introduction">
      <p>The GET method retrieves whatever information (in the form of an
      entity) is identified by the Request-URI.  If the Request-URI refers to a
      data-producing process, it is the produced data which shall be returned
      as the entity in the response and not the source text of the process,
      unless that text happens to be the output of the process.</p>

      <p>The semantics of the GET method change to a "conditional GET" if the
      request message includes an If-ModifiedSince, If-Unmodified-Since,
      If-Match, If-None-Match, or If-Range header field.  A conditional GET
      method requests that the entity be transferred only under the
      circumstances described by the conditional header field(s).  This reduces
      unnecessary network usage by allowing cached entities to be refreshed
      without requiring multiple requests or transferring data already held by
      the client.</p>

      <p>If a Range header field is included, the request is for only the part
      of the entity specified by the range header.  This allows partially
      retrieved entities to be completed without transferring previously
      received data.</p>
    </section>

    <section name="Typical Usage">
      <p>Typically the get method is used to download a document from a web
      server.  This can be achieved with the method, getResponseBody,
      getResponseBodyAsStream or getResponseBodyAsString.  Of these methods,
      getResponseBodyAsStream is generally the best choice as it avoids
      unnessecary buffering of all data into memory before processing.</p>

      <p>See the <a href="../tutorial.html">tutorial</a> for a full example
      of using the GET method.  There are also a number of examples in the <a
      href="http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/">sample
      code</a>.</p>

      <source><![CDATA[
        GetMethod get = new GetMethod("http://httpcomponents.apache.org");
        // execute method and handle any error responses.
        ...
        InputStream in = get.getResponseBodyAsStream();
        // Process the data from the input stream.
        get.releaseConnection();
        ]]>
      </source>
    </section>

    <section name="Common Problems">
      <p>The most common mistake when using the GET method is failing to read
      the entire response body even if an error code, redirect or any other
      response status is received.  As with all methods, one must also be sure to call 
      method.releaseConnection(), regardless of the response code received.</p>
    </section>

    <section name="RFC Section">
      <p>The get method is defined in section 8.1 of <a
      href="http://www.ietf.org/rfc/rfc1945.txt">RFC1945</a> and similarly
      defined for HTTP 1.1 in section 9.3 of <a
      href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>.</p>
    </section>

  </body>

</document>
