该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public static void main(String[] args) throws IOException {
//打开浏览器
CloseableHttpClient build = HttpClientBuilder.create().build();
//输入网址
HttpGet httpGet = new HttpGet("https://www.126.com/");
CloseableHttpResponse response=null;
//发送请求,获取内容,转格式utf-8
try {
response = build.execute(httpGet);
HttpEntity entity = response.getEntity();
String s = EntityUtils.toString(entity,"utf-8");
System.out.println(s);
} catch (IOException e) {
e.printStackTrace();
}
//关闭浏览器,释放资源
finally {
if (null!=response){
try {
response.close();
response=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if (httpGet!=null){
httpGet.releaseConnection();
}
if (build!=null){
build.close();
}
}
}