質問

I've got an UnknownHostException in my android application when I want to get to my web service.

I inserted an <uses-permission android:name="android.permission.INTERNET" /> at my AndroidManifest.xml.

If I go to my link of webservice via browser it's going fine.

I typed the domain name and IP at the C:\Windows\System32\drivers\etc\hosts file.

But if I run application via emulator I got an UnknownHostException. As I understand, emulator should use my system files to connect with the server...But, practically it doesn't..Help please with this issue.

役に立ちましたか?

解決 2

Problem solved using such domains as

CustomHttpClient.executeHttpPost("http//192.168.1.2/path"); 

Everything works fine with it. I can't edit hosts file in android file system even with root rights. So if you have similar problem - good solution is to use IP addresses, not domains.

Thanks to Haresh Chaudhary

他のヒント

In my case, I encountered this problem when I had started the emulator while I was logged on to a VPN. Logging off the VPN had no effect until I quit the emulator and restarted. It is easy to test if your emulator is not resolving names correctly - just go to the emulator browser and type in a website hostname (anything but Google's).

A very nice tutorial for connecting with the webservice is here

You will come through this line in this tutorial..

CustomHttpClient.executeHttpPost("http//192.168.1.2/path");  

here path means path of your file placed in htdocs.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top