如何处理 URLConnection 的连接超时错误(Java、Android)
我有以下代码:
try {
url = new URL(sURL);
URLConnection connection = url.openConnection();
connection.setConnectTimeout(1000);
connection.setReadTimeout(2000);
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
<从阅读器读取...> 捕获(IOException e){ e.printStackTrace(); 如何
检测连接超时问题?我想将此事件作为特殊情况来处理。 IOException 对于我的目的来说是通用的。
有什么帮助吗?
I have the following code:
try {
url = new URL(sURL);
URLConnection connection = url.openConnection();
connection.setConnectTimeout(1000);
connection.setReadTimeout(2000);
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
<Read from reader ...>
catch (IOException e) {
e.printStackTrace();
}
How can I detect connection-timeout issue? I would like to handle this event as a special case.
IOException is to general for my purpose.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)