java httpclient detect server disconnect
I'm doing a GET request with the apache HttpClient. Is there a way to detect when the serv开发者_JS百科er disconnects while reading from the InputStream?
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.
精彩评论