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
/** * httpclient cache mechanism */private static void Test25 () throws Clientprotocolexception, IOException {cacheconfig cacheconf IG = Cacheconfig.custom (). Setmaxcacheentries (1000)//MAX Cache 1000 object. Setmaxobjectsize (8192)/ /byte. build (); Requestconfig requestconfig = Requestconfig.custom (). Setconnecttimeout (30000)//Request time-out. Setsocket Timeout (30000)//Response time-out. Build (); A cached httpclient inherits all the configuration entries and parameters of the non-cached httpclient closeablehttpclient cachingclient = Cachinghttpclients.custom (). Setcacheconfig (CacheConfig). Setdefaultrequestconfig (Requestconfig). build (); Inherit httpclientcontext httpcachecontext context = Httpcachecontext.create (); HttpGet httpget = new HttpGet ("http://www.mydomain.com/content/"); Cachingclient.execute (httpget, context); Cacheresponsestatus responsestatus = Context.getcacheresponsestatus ();/** * This cache request is still printed multiple times "the response from the upstream server ~ ~", not the desired result * here Have a few questions: Whether the caching mechanism requires the client and the server to work together * Also, if this cache configuration does not take effect, is the official website code wrong? */switch (responsestatus) {case CACHE_HIT:System.out.println ("the corresponding is generated by the cache and no request is sent to the upstream ~ ~"); Break;case Cache_module_ RESPONSE:SYSTEM.OUT.PRINTLN ("The response is generated directly from the cache ~ ~"); Break;case CACHE_MISS:System.out.println ("The response from the upstream server ~ ~"); break;case VALIDATED:SYSTEM.OUT.PRINTLN ("The response is generated from the cache and verified to be from the source server ~"); }
Java:httpclient--the sixth chapter;