Use the HttpClient analog site login Post reply

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.