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);
...