最近在使用Apache的httpclient的时候,maven引用了最新版本4.3,发现Idea提示DefaultHttpClient等经常使用的类已经不推荐使用了,以前在使用4.2.3版本的时候,尚未被deprecated。去看了下官方文档,确实不推荐使用了,点击此处详情。 html
官方给出了新api的样例,以下。 apache
Get方法: api
CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://targethost/homepage"); CloseableHttpResponse response1 = httpclient.execute(httpGet); // The underlying HTTP connection is still held by the response object // to allow the response content to be streamed directly from the network socket. // In order to ensure correct deallocation of system resources // the user MUST either fully consume the re继续阅读→socket