How do you connect localhost in the Android emulator?

Dharmendra picture Dharmendra · Apr 3, 2011 · Viewed 114.5k times · Source

I have made a php script inside localhost and I am connecting that with httpClient but I am getting a problem.

Please tell me how can I connect to a php file at localhost from the emulator?

Answer

lampShaded picture lampShaded · Jun 10, 2011

Use 10.0.2.2 to access your actual machine.

As you've learned, when you use the emulator, localhost (127.0.0.1) refers to the device's own loopback service, not the one on your machine as you may expect.

You can use 10.0.2.2 to access your actual machine, it is an alias set up to help in development.