互联网连接错误 [英] Internet Connection Error

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

问题描述

我有一个Android应用程序,连接到互联网。我捕获所有可能的方案进行连接,并注意到,当我没有连接到Internet,一个的UnknownHostException 抛出。我有点困惑在这里,因为得到一个的UnknownHostException 将意味着应用程序能够连接到互联网,但无法找到指定的URL。

我会得到正确的异常?你能解释一下为什么我在这得到一个的UnknownHostException

另外,你能告诉具体例外这些场景:

  • 当没有互联网连接。
  • 当URL不能被发现。
  • 当请求超时。
  • 当网站已关闭。
  • 在当前访问被拒绝。

我也要AP preciate它,如果你能给我更多的场景和例外。我必须捕获所有可能的连接,并显示最合适的信息取决于连接错误的类型。

解决方案
  

让一个UnknownHostException将意味着该应用程序是   能够连接到互联网

没有事实并非如此。这意味着应用程序无法解析主机名。这可能是因为主机名不存在,或者是因为它无法连接到互联网来解决这个问题。

 当没有互联网连接。
 

没有特定的异常。 没有因特网连接并没有一个明确的含义。条件解析为低于其它故障模式之一

 当URL无法找到。
 

如果在主机的都找不到,的UnknownHostException 。如果URL的内容部分找不到,HTTP 404

 当请求超时。
 

的ConnectException 与连接超时的消息,或 SocketTimeoutException如果如果它是一个读取超时。

 当网站已关闭。
 

的ConnectException 与连接被拒绝的消息。

 当访问被拒绝。
 

HTTP 403。

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.

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

Also, can you tell the specific Exceptions for these scenarios:

  • 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.

解决方案

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

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.

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 with 'connection timed out' as the message, or SocketTimeoutException if it's a read timeout.

When the website is down.

ConnectException with 'connection refused' as the message.

When access is denied.

HTTP 403.

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

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