最近在使用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