Java:httpclient--the seventh chapter;

Source: Internet
Author: User


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;

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.