我可以使用Android模拟器访问我的笔记本电脑web服务器,我使用10.0.2.2:portno 工作得很好。

但当我连接真正的Android手机时,手机浏览器无法连接到我笔记本电脑上的同一个web服务器。手机和笔记本电脑通过USB线连接。如果我运行 adb devices命令,我可以看到我的手机。

我错过了什么?


当前回答

虽然有一个答案已经被接受,但这对我来说很管用:

Make sure both your computer and android device are on same network. get your computer's ip address. (in case of mac type ifconfig inside terminal and look for en0/en1 -> inet it should be something like 19*.16*.1.4.) (on windows, use `ipconfig) Open your mobile settings and go to network-> long press your wifi network-> modify network -> scroll down to advanced options -> chose proxy manual and in proxy hostname type your address i.e. 19*.16*.1.4 inside port enter your port. and save it. search for what is my ip in google chrome, and get your ip, lets say it is 1**.1**.15*.2** try accessing 1**.1**.15*.2**:port/ from your mobile device.

事情就是这么简单。

其他回答

虽然有一个答案已经被接受,但这对我来说很管用:

Make sure both your computer and android device are on same network. get your computer's ip address. (in case of mac type ifconfig inside terminal and look for en0/en1 -> inet it should be something like 19*.16*.1.4.) (on windows, use `ipconfig) Open your mobile settings and go to network-> long press your wifi network-> modify network -> scroll down to advanced options -> chose proxy manual and in proxy hostname type your address i.e. 19*.16*.1.4 inside port enter your port. and save it. search for what is my ip in google chrome, and get your ip, lets say it is 1**.1**.15*.2** try accessing 1**.1**.15*.2**:port/ from your mobile device.

事情就是这么简单。

因为这是一个老问题,有一个新的方法来做这个非常非常简单。下载ADB Chrome扩展,然后按照这些说明:

https://developers.google.com/chrome-developer-tools/docs/remote-debugging

另一件需要检查的事情是,当同时启用2.4G和5G且设备处于不同频率时,一些路由器在桥接请求方面存在问题。尝试禁用其中一个频率,以便两个设备连接到同一个接口。

在Ilya Saunkin回答的基础上,这里有一个命令,应该输出你的IP地址格式为超链接-只需用3000代替你的端口号:

ifconfig | grep "inet " | grep -v 127.0.0.1 | sed 's/netmask.*//g' | sed 's/inet//g' | awk '{print "http://"$1":3000/"}'

根据您运行命令的位置,您应该能够(在Mac上)按住命令键并单击/双击打开链接。

使用netconfig xml并在manifest.xml中分配它是最好的解决方法。这将绕过android默认的https限制。