java httpclient检测服务器断开连接
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
输入流上的 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.
当然,请查看异常处理部分文档。
Sure, check out the Exception Handling section of the docs.