I am trying to connect to a web application running on my computer with an Android emulator using apache httpClient .
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 have the required Android manifest configuration below:
<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 checked that I can access the Internet from a browser on the emulator. I also cannot access the application url from the browser. My application also fails with an error
java.net.UnknownHostException: unable to execute host "dev.example.com": no address associated with host name
My application works great when used with the IP address of my computer. I also have an entry in my hosts file
192.168.1.8 dev.example.com
What can I skip here? It seems that the Android emulator cannot find my host file to resolve the host name!
source share