Httclient Normal Process
1. Create HttpClient instances
New= httpclients.createdefault ();
2. Create a Request instance
Newnew httppost (URL);
3. Supplementary header information (optional)
Httppost.addheader ("Referer", "http://iservice.10010.com/e4/query/basic/history_list.html"); Httppost.addheader ("Cookie", "td_cookie=18446744072103645798; mallcity=31|310; ");
4. Supplementary Request entity
1) The URL is a restful style that already contains the parameters that need to be passed in. You can skip the direct to the next action.
2) Form
New Arraylist<namevaluepair>(); Nvps.add (new basicnamevaluepair ("QueryType", "0001")); Nvps.add(new Basicnamevaluepair ("Querycode", "0001")); Nvps.add (New Basicnamevaluepair ("Billdate", "201608")) Nvps.add (new Basicnamevaluepair ("Flag", "2")); Httppost.setentity (new urlencodedformentity (Nvps));
5. Request execution
HttpResponse response == httpclient.execute (httpget); byte [] response = Httpclient.execute (Httpget,handler);
6. Read the response content
if (Response.getstatusline (). Getstatuscode () = = response.getentity (); if NULL ) { = entity.getcontent (); Try { // do something useful finally { instream.close ( ); } }
7. Release the connection
The jar to be referenced
<!--httpclient-- <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.3.4</version> </ Dependency> <!--httpclient--
HttpClient 4.0 Use