我可以使用Android模拟器访问我的笔记本电脑web服务器,我使用10.0.2.2:portno 工作得很好。
但当我连接真正的Android手机时,手机浏览器无法连接到我笔记本电脑上的同一个web服务器。手机和笔记本电脑通过USB线连接。如果我运行 adb devices命令,我可以看到我的手机。
我错过了什么?
我可以使用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.
事情就是这么简单。
其他回答
它非常简单,- GOTO命令行(Window + R [type cmd]) - type ipconfig,这将显示您PC的当前IP地址-将该IP地址写在您的Android手机浏览器上:80例如(http://192.168.x.x:80)
Done
localhost将出现在你的手机上
为未来的开发人员添加解决方案。
ip地址的副本地址。右键单击您的网络->网络和共享->单击您当前拥有的连接->详细信息->然后ipv4地址旁边的地址是您的IP地址,请在某处注意这一点
进入控制面板->系统和安全-> windows防火墙->高级设置->入站规则->新规则(按照步骤添加端口,例如80,它真的很简单)
将您在手机浏览器中记下的IP地址和您为其创建规则的端口号放在旁边。例如192.168.0.2:80和wala。
可能的解决方案,如果它不连接。 右键点击网络->打开网络和共享->查看您的活动连接,在您的连接类型的名称下单击它,如果它是公共的,并确保将其更改为家庭网络。
在创建应用程序时,使用移动设备调试或渲染是很有帮助的。可以使用带有端口号的IPv4地址通过手机访问系统localhost。需要注意的是,为了实现这一点,两台设备都应该连接到同一个wifi或网络,并且机器的网络应该是私有的。
虽然有一个答案已经被接受,但这对我来说很管用:
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.
事情就是这么简单。
首先,让你的机器(服务器运行的地方)IP地址是静态的。在android代码中输入此静态IP地址。 接下来进入你的wifi路由器接口,检查左边的面板。您将看到端口转发/转发等选项。点击它并转发端口80。 现在编辑httpd .conf文件,并将其编辑为
所有人允许
. 重新启动服务器。现在一切都可以正常工作了。
此外,您可以保留您的机器的IP地址,以便始终分配给您。 在路由器接口的左面板中,找到DHCP -> Address Reservation,单击它。输入计算机的MAC地址和您在代码中输入的IP地址。单击保存。这将为您的机器保留给定的IP地址。