closeablehttpclient 没close
时间: 2023-09-14 18:13:36 浏览: 104
CloseableHttpClient是HttpClient的子接口,它实现了HttpClient接口,具有HttpClient的优势。它可以实现自动关闭连接,通过实现Closeable接口的close方法来关闭连接池。此外,CloseableHttpClient还可以构建多线程并发环境,可以创建多个实例来处理任务,并通过close方法关闭连接,释放资源。\[1\]
在最新版本的HttpClient中,使用的是CloseableHttpClient而不是以前的DefaultHttpClient。自4.3版本之后,CloseableHttpClient开始出现。而之前的HttpClient不能使用SSL证书验证。\[2\]
如果你想使用CloseableHttpClient,你需要在项目的依赖中添加相应的库。例如,在Maven项目中,你可以添加以下依赖项:
```xml
<!-- HTTP Client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-cache</artifactId>
<version>4.5.10</version>
<optional>true</optional>
</dependency>
```
这样就可以使用CloseableHttpClient,并在使用完毕后调用close方法来关闭连接了。\[3\]
#### 引用[.reference_title]
- *1* [【项目实战】为什么我选择使用CloseableHttpClient,而不是HttpClient,他们俩有什么区别?](https://blog.csdn.net/wstever/article/details/129282437)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [CloseableHttpClient](https://blog.csdn.net/walle167/article/details/50957400)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [CloseableHttpClient 了解](https://blog.csdn.net/u010738038/article/details/130708932)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文