How do you connect localhost in the Android emulator?

落花浮王杯 提交于 2019-11-26 03:33:29

问题


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?


回答1:


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.




回答2:


Use 10.0.2.2 for default AVD and 10.0.3.2 for Genymotion




回答3:


Thanks, @lampShaded for your answer.

In your API/URL directly use http://10.0.2.2:[your port]/ and under emulator setting add the proxy address as 10.0.2.2 with the port number. For more, you can visit: https://developer.android.com/studio/run/emulator-networking.html




回答4:


Instead of giving localhost give the IP.




回答5:


you should change the adb port with this command:

adb reverse tcp:8880 tcp:8880; adb reverse tcp:8081 tcp:8081; adb reverse tcp:8881 tcp:8881


来源:https://stackoverflow.com/questions/5528850/how-do-you-connect-localhost-in-the-android-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!