How to connect to my http://localhost web server from Android Emulator

前端 未结 11 1748
礼貌的吻别
礼貌的吻别 2020-11-22 02:03

What can I do in the Android emulator to connect it to my localhost web server page at http://localhost or http://127.0.0.1?

I\'ve tried it

11条回答
  •  醉酒成梦
    2020-11-22 02:22

    You can actually use localhost:8000 to connect to your machine's localhost by running below command each time when you run your emulator (tested on Mac only):

    adb reverse tcp:8000 tcp:8000
    

    Just put it to Android Studio terminal.

    It basically sets up a reverse proxy in which a http server running on your phone accepts connections on a port and wires them to your computer or vice versa.

提交回复
热议问题