Import org.apache.http.HttpEntity;
Import Org.apache.http.client.methods.HttpGet;
Import org.apache.http.impl.client.CloseableHttpClient;
Import org.apache.http.impl.client.HttpClients;
Import Org.apache.http.util.EntityUtils;
Import java.io.IOException;
/**
* Created by Administrator on 2018/4/11.
*/
public class Httpclienttest {
public static void Main (string[] args) {
try {
String charset = "UTF-8";
Create Closeablehttpclient
Closeablehttpclient httpClient = Httpclients.custom (). build ();
String url = "Http://www.baidu.com";
If there are parameters, directly after the URL plus the number stitching such as http://www.baidu.com?a=n&b=n
Request method
HttpGet get = new HttpGet (URL);
Receive Request return object
Httpentity entity =httpclient.execute (GET). GetEntity ();
Use Entityutils to read the httpentity request return stream into a string
String result = entityutils.tostring (Entity,charset);
SYSTEM.OUT.PRINTLN (result);
Entityutils.consume (entity);
Httpclient.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
}
HttpClient How to send a GET request