HttpClient--the first chapter;
HttpClient--chapter II;
HttpClient explanation--chapter three;
HttpClient--the fourth chapter;
HttpClient--the fifth chapter;
HttpClient--the sixth chapter;
HttpClient--the seventh chapter;
Compared to HttpURLConnection, httpclient richer, and more powerful, of which Apache has two items are httpclient, one is the commonts package, this is universal, More professional is the org.apache.http, so I generally use the latter;
HttpClient can handle long connections, save sessions, reconnect, and request filters, connection reuse, etc...
Here is the test code (all summarized from the official documentation, as well as the translation)
Need to download Core package: Httpclient-4.3.4.jar, can also be downloaded on the official website: http://hc.apache.org/downloads.cgi
/** * */private static void Test26 () throws Clientprotocolexception, ioexception{//closeablehttpclient httpclient = Httpc Lients.createdefault (); Httpclientcontext context = Httpclientcontext.create (); HttpGet httpget = new HttpGet ("Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getDatabaseInfo"); Closeablehttpresponse response = Httpclient.execute (httpget, context); try {//Principal Principal = Context.getusertoken (Principal.class); SYSTEM.OUT.PRINTLN (principal); } finally {//Response.close (); }closeablehttpclient httpclient = Httpclients.createdefault (); Httpclientcontext context1 = Httpclientcontext.create (); HttpGet Httpget1 = new HttpGet ("Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getDatabaseInfo"); Closeablehttpresponse response1 = Httpclient.execute (Httpget1, CONTEXT1); try {httpentity entity1 = response1.getentity (); } finally {response1.close (); } Principal Principal = Context1.getusertoken(Principal.class); Httpclientcontext context2 = Httpclientcontext.create (); Context2.setusertoken (principal); HttpGet Httpget2 = new HttpGet ("Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getDatabaseInfo"); Closeablehttpresponse Response2 = Httpclient.execute (Httpget2, CONTEXT2); try {httpentity entity2 = response2.getentity (); } finally {response2.close (); }}
Java:httpclient--the seventh chapter;