andoird & libcurl - problems connecting to a localhost web service

andoird & libcurl - problems connecting to a localhost web service
0.0 0


Hi guys, I’ve managed to connect my app to a web service but I have a problem with the android platform.

Right now, the web service is hosted at “” at localhost.

I’ve managed to generate requests for it and it works great in the win32 app. The problem comes when I try to connect to the web service with the android app. It will always give “code: 7” (couldn’t connect) but the funny thing is that it will work if I connect to whatever web page.

So I wonder why it won’t let me connect to localhost, also note that I’m using the emulator since I don’t have a device.

Any ideas?


Check this

Seems that android maps your PC to ip, at least when running through emulator.
Or else find the local IP of your PC (probably 192.168.1.XX) and use that instead.


You could also try adding a line in etc/hosts to map localhost to a fake web address


Hi danadn _,

May i know how you managed to connect your app to a web service? I need help in that.
Any sample code or link will be great.
I never deal with web service before.



Hi smit, first of all I was asking for connecting to a webserver hosted on localhost. When accessing from your app inside the emulator the localhost is, in fact, the emulator.

To let the emulator access the webserver hosted on you PC you have to use So for example if you are trying two builds of your app, one for Win32 and one for Android, you can do this:

curl_easy_setopt(curl, CURLOPT_URL, ""); 
curl_easy_setopt(curl, CURLOPT_URL, ""); 

Hope it helps.