Commons Http Client is a HTTP agent implementation in java supporting
client-side authentication, HTTP state management and HTTP connection management.
This requires the libraries httpclient-4.1.2.jar, httpcore-4.1.2.jar,
httpmime-4.1.2.jar, httpclient-cache-4.1.2.jar, commons-codec.jar and
commons-logging-1.1.1.jar to be in classpath.
The following example shows how to make Http Head request through Http Client.
/**
* The HEAD method is identical to GET except that the server MUST NOT
* return a message-body in the response. The meta-information contained
* in the HTTP headers in response to a HEAD request SHOULD be identical to
* the information sent in response to a GET request. This method can be
* used for obtaining meta-information about the entity implied by the
* request without transferring the entity-body itself.
*
* This method is often used for testing hypertext links for validity,
* accessibility, and recent modification.
*
* - Source www.w3.org
*/ public class HeadRequestTest {
/**
* @param args
*/ public static void main(String[] args) {
HttpClient httpclient = new DefaultHttpClient();
HttpHead httphead = new HttpHead("http://finance.google.com/finance/info?client=ig&q=NASDAQ:GOOG");
System.out.println("Requesting : " + httphead.getURI());
System.out.println("\n\nResponse : "); if (response.getEntity() != null) {
System.out.println(EntityUtils.toString(response.getEntity()));
} else {
System.out.println("As expected no response body for HEAD request");
}