HttpClient is a subproject under Apache Jakarta Common that can be used to provide a client-side programming toolkit that supports HTTP protocols, simulating the behavior of browsers. It provides a number of ways to simplify network access, although most of the functionality can be implemented using a lower-level java.net.HttpURLConnection. For example:
Implements all HTTP methods (Get,post, etc.)
Support HTTPS Protocol
Support Proxy Server
Automatic maintenance of Cookies, etc.
We know that the HTTP protocol is for connectionless, to maintain the session, now basically using cookies based on the way (sessions are also implemented via cookies), so httpclient automatic maintenance Cookies to our login post reply to the non- Often used (general website need to log in and post a reply).
The following examples are implemented using the Commons-httpclient-3.1.jar package (although the commons-httpclient-4.0 has been released, the code has undergone a major refactoring, and the invocation method has changed significantly).
The path to the download Jar package is: http://hc.apache.org/downloads.cgi
Because HttpClient uses the subprojects logging and codec under Apache Jakarta Common, you also need to download these two packages in http://commons.apache.org/:
Commons-logging.jar
Commons-codec-1.3.jar
To better understand the code, the UML class diagram is designed as follows:
The sequence diagram for the method call is as follows: