An HTTP Client built with Apache Commons HttpClient classes

This web page publishes a Java HTTP POST client that uses the Apache Commons HttpClient classes (Commons is a subproject of the Apache Jakarta project). The HTTP POST client sends POST messages to a defined URL and reads the response. This POST client not only handles the HTTP transaction, it also handles timeout in the case where the HTTP transaction hangs on an unresponsive URL (an unresponsive IP address, for example).

Before I learned about the Apache Commons HttpClient classes, I wrote a class that I named SynchronousHttp to handle HTTP POST operations and return a result (for an example of a class that uses the SynchronousHttp class see EchoClient). The SynchronousHttp class uses the standard Java libraries. The Apache Commons HttpClient class allow the details of these classes to be abstracted so writing a class like SynchronousHttp is unnecessary. The HttpClient libraries also provide support for handling HTTP timeouts.

To compile and run the HTTP POST client code you will need to download the Apache Commons HttpClient and Logging ".jar" files. You should make sure that these .jar files are defined in your CLASS_PATH environment variable. These Apache .jar files can be obtained from:

I've written three classes to show how to use some of the HttpClient classes:

Ian Kaplan, October 2004
Last revised:

back to Java page