HttpClient (4.3.5)-simple example

Source: Internet
Author: User

HttpClient is a client-side HTTP Transport Library, not a browser. The purpose of the HttpClient is to transmit and receive HTTP messages. HttpClient does not attempt to process the message content, execute JavaScript scripts embedded in HTML, or guess that the entity content type is equal to the HTTP transport-independent operation.

Examples of HttpClient use

//Creating an HttpClient instanceCloseablehttpclient httpClient =Httpclients.createdefault ();//create an instance of an HTTP GET requestHttpGet HttpGet =NewHttpGet ("http://www.example.com/"); //send request and get HTTP responseCloseablehttpresponse response =Httpclient.execute (httpget);Try {    //print the starting line of the response messageSystem.out.println (Response.getstatusline ()); //print the header of the response messageheader[] headers =response.getallheaders ();  for(Header header:headers) {System.out.println (Header.getname ()+ ": " +Header.getvalue ()); } System.out.println (""); //the body of the printed messagehttpentity entity =response.getentity (); if(Entity! =NULL) {System.out.println (entityutils.tostring (entity)); }} finally{response.close ();}

HttpClient (4.3.5)-simple example

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.