简体   繁体   English

Android “主机未知”错误

[英]Android "Host is Unknown" Error

I'm getting an error from Android that "Host is unknown server:80".我从 Android 收到一条错误消息,指出“Host is unknown server:80”。 I'm trying to access a WCF Rest service on a server from Android Emulator on a virtual machine.我正在尝试从虚拟机上的 Android 模拟器访问服务器上的 WCF Rest 服务。 Is this scenario supported?是否支持此场景? BTW, I can access the help page of the service, so I know the service is working.顺便说一句,我可以访问该服务的帮助页面,所以我知道该服务正在运行。 And I can access it from that virtual machine.我可以从那个虚拟机访问它。

Any help is appreciated.任何帮助表示赞赏。 My development environment is Windows 7 64 BIT, using latest Eclipse version.我的开发环境是Windows 7 64 BIT,使用最新的Eclipse版本。 The services is on a Win 2008 R2 machine.该服务位于 Win 2008 R2 机器上。

My guess is that you have incorrectly configured the hostname.我的猜测是您错误地配置了主机名。

Based on the error message, it looks as if you have supplied ":80" as a hostname or IP address.根据错误消息,您似乎提供了“:80”作为主机名或 IP 地址。 If the platform thought that that string was supposed to be a DNS name and tried to do a DNS lookup, and the lookup would fail resulting in a "unknown host" diagnostic of some kind.如果平台认为该字符串应该是 DNS 名称并尝试执行 DNS 查找,查找将失败,导致某种“未知主机”诊断。

If this is what the problem is, then there are a couple of observations.如果这就是问题所在,那么有几个观察结果。

  • If you are trying to refer to "this device" in a static config file (or whatever), you can use its hostname or IP address (if you know them), or the IP address of the loopback interface which is (most likely) "127.0.0.1".如果您试图在 static 配置文件(或其他任何文件)中引用“此设备”,则可以使用其主机名或 IP 地址(如果您知道),或环回接口的 IP 地址(最有可能) “127.0.0.1”。 An empty String probably won't work.空字符串可能不起作用。

  • The port number (eg "80") should not be included in a hostname / IP address... unless you are parsing it out before you do the host string resolution.端口号(例如“80”)不应包含在主机名/IP 地址中...除非您在执行主机字符串解析之前将其解析出来。

Once potential cause of this error is forgetting to include the inte.net permission or not putting it in the right place.一旦这个错误的潜在原因是忘记包含 inte.net 权限或没有把它放在正确的地方。 Make sure you have the following in your manifest.xml, outside of the application tags:确保在应用程序标签之外的 manifest.xml 中包含以下内容:

<uses-permission android:name="android.permission.INTERNET"/>

I had to use the 10.0.2.2 alternative IP since the emulator uses the localhost IP.我不得不使用10.0.2.2 替代方案 IP ,因为模拟器使用本地主机 IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM