HttpClient Introduction
The HTTP protocol is probably the most frequently used and important protocol on the Internet today, and more and more Java applications need to access network resources directly through the HTTP protocol. Although the basic functionality of accessing the HTTP protocol has been provided in the JDK's java.net package, the JDK library itself offers not enough functionality and flexibility for most applications. HttpClient is a subproject under Apache Jakarta Common that provides an efficient, up-to-date, full-featured client-side Programming toolkit that supports HTTP protocols, and it supports the latest versions and recommendations of the HTTP protocol. HttpClient has been used in a number of projects, such as the other two famous Jakarta on the Apache Cactus and Htmlunit are using httpclient, and more httpclient applications can see HTTP://WI Ki.apache.org/jakarta-httpclient/httpclientpowered. The HttpClient project is very active and there are still a lot of people using it. The current HttpClient version was released in 2005.10.11 by 3.0 RC4.
HttpClient Function Introduction
The following are the main features provided by HttpClient, and more detailed features can be found in the HttpClient home page.
Implements all HTTP methods (Get,post,put,head, etc.)
Support for automatic steering
Support HTTPS Protocol
Support Proxy Server, etc.
The following describes how to use these features. First of all, we must install good httpclient.
HttpClient can be downloaded in http://jakarta.apache.org/commons/httpclient/downloads.html
HttpClient used the sub-project logging under Apache Jakarta Common, you can http://jakarta.apache.org/site/downloads/downloads_ from this address commons-logging.cgi download to common logging, remove Commons-logging.jar from the downloaded Zip pack and add to CLASSPATH
HttpClient used the sub-project codec under Apache Jakarta Common, you can http://jakarta.apache.org/site/downloads/downloads_ from this address commons-codec.cgi download to the latest common codec, remove Commons-codec-1.x.jar from the downloaded Zip pack and add it to the CLASSPATH
The use of HttpClient basic functions
Get method
The following 6 steps are required to use HttpClient:
1. Create an instance of HttpClient
2. Create an instance of a connection method, here is GetMethod. To pass in an address to be connected in the GetMethod constructor
3. Invoke the Execute method of the instance created in the first step to perform the example created in step two
4. Read response
5. Release the connection. The connection must be released, regardless of whether the execution method succeeds
6. Processing of the resulting content