Internet连接错误 [英] Internet Connection Error

查看:271
本文介绍了Internet连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到互联网的Android应用程序。我陷入所有可能的情况下的连接,并注意到,当我没有互联网连接, UnknownHostException 抛出。我有点困惑在这里,因为得到 UnknownHostException 将意味着应用程序能够连接到互联网,但无法找到给定的URL。

I have an Android application which connects to the Internet. I am trapping all the possible scenarios for the connection and notice that when I don't have an Internet connection, an UnknownHostException is thrown. I am a bit confused here since getting an UnknownHostException will mean that the application was able to connect to the Internet but wasn't able to find the given URL.

我得到正确的异常吗?你能解释为什么我在这里得到 UnknownHostException 吗?

Am I getting the right Exception? Could you explain why am I getting an UnknownHostException in this?

方案:


  • 当没有互联网连接时。

  • 当找不到URL时。 / li>
  • 当请求超时时。

  • 当网站关闭时。

  • / li>
  • When there is no Internet connection.
  • When the URL cannot be found.
  • When the request timed out.
  • When the website is down.
  • When access is denied.

如果你能给我更多的场景和异常,我也很感激。我必须捕获所有可能的连接,并根据连接类型显示最合适的消息错误。

I would also appreciate it if you could give me more scenarios and Exceptions. I have to trap all the possible connections and display the most appropriate message depending on the type of connection Error.

推荐答案


获取UnknownHostException意味着应用程序是
能够连接到Internet

getting an UnknownHostException will mean that the application was able to connect to the Internet

t。这意味着应用程序无法解析主机名。这可能是因为主机名不存在,或者因为它无法连接到互联网来解决它。

No it doesn't. It means the application was unable to resolve the host name. That could be because the host name doesn't exist, or because it was unable to connect to the Internet to resolve it.


没有互联网连接。

When there is no Internet connection.

没有特定的例外。 没有互联网连接没有明确定义的意义。条件解析为以下其他失败模式之一。

No specific exception. "There is no Internet connection" doesn't have a well-defined meaning. The condition resolves to one of the other failure modes below.


无法找到网址时

When the URL cannot be found.

如果找不到主机 UnknownHostException 。如果无法找到网址的内容部分,HTTP 404。

If the host cannot be found, UnknownHostException. If the content part of the URL cannot be found, HTTP 404.


请求超时时。

When the request timed out.

ConnectException 以连接超时作为消息,或 SocketTimeoutException

ConnectException with 'connection timed out' as the message, or SocketTimeoutException if it's a read timeout.

ConnectException 作为邮件使用连接被拒绝。

ConnectException with 'connection refused' as the message.


拒绝访问。

When access is denied.

HTTP 403。

这篇关于Internet连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆