问题
I have a HTTP server working on my android emulator listening to port 8080. How can I connect to it from same PC's browser? I tried 127.0.0.1 but it couldn't connect.
回答1:
You have to enable port forwarding in adb
. For example:
adb forward tcp:8080 tcp:8080
This will forward incoming connections to localhost TCP/8080 to the emulator TCP/8080.
Here's the reference.
回答2:
You can use 10.0.2.2 to access your actual machine, it is an alias set up to help in development.
来源:https://stackoverflow.com/questions/14684411/how-to-connect-to-a-http-server-running-in-android-emulator