The seven types of weapons used by Apache Common httpclient

Source: Internet
Author: User

1. The Get/post of the Fist

Fist is the most basic heavy weapons, but also the most important, like martial arts people must first firm stance.

Java code

HttpClient httpclient=new httpclient ();//Create a client, similar to opening a browser

GetMethod getmethod=new GetMethod ("http://www.blablabla.com");//Create a Get method, similar to entering an address in the browser's address bar

int Statuscode=httpclient.executemethod (GetMethod);/enter--punch!

System.out.println ("response=" + getmethod.getresponsebodyasstring ()); see the fist hit situation, you can get a lot of things, such as head, cookies and so on

Getmethod.releaseconnection ()/release, remember to punch

2. The support of Peacock Ling HTTPS

How do I support HTTPS?

Java code

static{
  Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
  Protocol.registerProtocol("https", easyhttps);
}

Before executing the specific HTTP method, the HTTPS protocol will be registered secretly, such as the Peacock Ling hidden Mystery, kill the enemy in the invisible. Remember, the official binary release has no SSL contribute package, one way is to download the source code version to create your peacock feather.

3. The cookies of the sentimental ring

Often Taoist old amorous, in fact, is too much memory, so the feelings of the place, just as cookies sweetheart, no matter where you go, always put you worried:

Java code

HttpClient httpclient=new HttpClient();
httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);//RFC_2109是支持较普遍的一个,还有其他cookie协议
HttpState initialState = new HttpState();
Cookie cookie=new Cookie();
cookie.setDomain("www.balblabla.com");
cookie.setPath("/");
cookie.setName("多情环");
cookie.setValue("多情即无情");
initialState.addCookie(cookie);
httpclient.setState(initialState);
...

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.