简体   繁体   English

Android:模拟器无法解析本地工作站的主机名

[英]Android: emulator unable to resolve hostname for local workstation

I'm trying to connect to a web app running my computer from the android emulator using the apache httpClient . 我正在尝试使用apache httpClient从Android模拟器连接到运行我的计算机的Web应用程序。

HttpPost post = new HttpPost("http://dev.example.com:8443/gatekeeper/rs/authenticate/login");
post.setHeader("Content-type","application/x-www-form-urlencoded");
post.setEntity(new UrlEncodedFormEntity(formparams));
HttpClient client=new DefaultHttpClient();
response = client.execute(post);

I do have the required android manifest configuration as below 我确实有如下所示的Android清单配置

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I did check I can access the internet from the browser on the emulator. 我确实检查过我可以从模拟器上的浏览器访问互联网。 I can not access the app URL from the browser as well. 我也无法从浏览器访问应用程序URL。 My application also fails with an error 我的应用程序也失败并出现错误

java.net.UnknownHostException: Unable to resolve host "dev.example.com": No address associated with hostname java.net.UnknownHostException:无法解析主机“dev.example.com”:没有与主机名关联的地址

My application works fine when used with IP address of my computer. 我的应用程序与我的计算机的IP地址一起使用时工作正常。 I also have entry in my hosts file 我的主机文件中也有条目

192.168.1.8 dev.example.com 192.168.1.8 dev.example.com

What can I be missing here? 我在这里可以缺少什么? It looks like android emulator can't look in to my hosts file to resolve the host name! 看起来android模拟器无法查看我的hosts文件来解析主机名!

Please check the Connectivity programitically before calling for response 在请求回复之前,请以程序方式检查Connectivity

or If there is no response the also this exception is thrown 或者如果没有响应,则抛出此异常

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

相关问题 Java无法解析主机名 - Java unable to resolve hostname JSOUP和Android模拟器-无法解析主机 - JSOUP and Android Emulator - unable to resolve host Android中使用主机名的本地网络 - Local Networking with Hostname in Android IOException无法解析主机,没有与主机名关联的地址 - IOException Unable to resolve host,No address associated with hostname 无法解析主机:没有与主机名关联的地址 - Unable to resolve host: No address associated with hostname Android API 23 java.net.UnknownHostException:无法解析主机“URL”:没有与主机名关联的地址 - Android API 23 java.net.UnknownHostException: Unable to resolve host “URL”: No address associated with hostname Android改装-HTTP失败:java.net.UnknownHostException:无法解析主机{我的基本url}:没有与主机名关联的地址 - Android Retrofit - HTTP FAILED: java.net.UnknownHostException: Unable to resolve host {my base url}: No address associated with hostname 无法解析主机“mywebsite.com”:没有与主机名关联的地址 - Unable to resolve host “mywebsite.com”: No address associated with hostname java.net.UnknownHostException:无法解析主机没有与主机名关联的地址 - java.net.UnknownHostException: Unable to resolve host No address associated with hostname 将android模拟器指向本地域 - Point android emulator to local domain
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM