HTTPClient的使用

引入

在pom.xml插入:

1
2
3
4
5
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public static String doGet(URL url) throws Exception {
String content;
HttpHost proxyHost = new HttpHost("127.0.0.1",7890);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
CloseableHttpClient httpclient = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();
HttpGet httpGet = new HttpGet(url.toString());
CloseableHttpResponse response = null;
try {

response = httpclient.execute(httpGet);
content = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println("内容长度:" + content.length());
return content;

} finally {
if (response != null) {
response.close();
}
httpclient.close();
}

}
作者

PP_ROCKET

发布于

2022-02-11

更新于

2022-05-22

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论