java httpclient检测服务器断开连接

发布于 2024-11-18 22:30:19 字数 76 浏览 2 评论 0原文

我正在使用 apache HttpClient 执行 GET 请求。有没有办法在从 InputStream 读取时检测服务器何时断开连接?

I'm doing a GET request with the apache HttpClient. Is there a way to detect when the server disconnects while reading from the InputStream?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残月升风 2024-11-25 22:30:19

输入流上的 EOS(read() 返回 -1,readLine() 返回 null,readXXX() 对于任何其他 XXX 抛出 EOFException)是主要机制,否则是 IOException,通常是“连接重置”。您很少会看到 SocketException。如果您使用读取超时,则会出现 SocketTimeoutException。

EOS on the input stream (read() returning -1, readLine() returning null, readXXX() throwing EOFException for any other XXX) is the primary mechanism, otherwise an IOException, typically 'connection reset'. Very rarely you may see a SocketException. If you are using read timeouts, a SocketTimeoutException.

等你爱我 2024-11-25 22:30:19

当然,请查看异常处理部分文档。

Sure, check out the Exception Handling section of the docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文