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.

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.

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.

Typical Usage

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.

See the tutorial for a full example of using the GET method. There are also a number of examples in the sample code.

        GetMethod get = new GetMethod("");
        // execute method and handle any error responses.
        InputStream in = get.getResponseBodyAsStream();
        // Process the data from the input stream.

Common Problems

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.

RFC Section

The get method is defined in section 8.1 of RFC1945 and similarly defined for HTTP 1.1 in section 9.3 of RFC2616.