2022-02-11发表2022-05-22更新几秒读完 (大约82个字)HTTPClient的使用引入在pom.xml插入: 12345<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.13</version></dependency> 使用123456789101112131415161718192021222324public 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(); }}