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

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

我错过了什么?


当前回答

这些回答中没有一个提到从Windows防御防火墙打开Apache HTTP服务器。使用XAMPP v. 5.6.40,您可以尝试以下解决方案:

Go to Windows Defender Firewall, click on Inbound rules and look for Apache HTTP Server. There will be two instances of this rule. Double click on it and set the Action to Allow the connection. Go to the Advanced tab and tick Domain, Private, and Public options from the Profiles section. Go to the Protocols and Ports tab and configure your local ports. By default, XAMPP server runs on port 80. If you're using multiple ports for web development, simply place commas after each port. Save your changes. Run cmd and type ipconfig. Take note of your IP Address. Restart Apache from your XAMPP Control Panel. Try accessing your app via address:port/path, where address is your IP address, port is your port (80 in most cases), and path to your project in /xampp/htdocs.

其他回答

首先,让你的机器(服务器运行的地方)IP地址是静态的。在android代码中输入此静态IP地址。 接下来进入你的wifi路由器接口,检查左边的面板。您将看到端口转发/转发等选项。点击它并转发端口80。 现在编辑httpd .conf文件,并将其编辑为

所有人允许

. 重新启动服务器。现在一切都可以正常工作了。

此外,您可以保留您的机器的IP地址,以便始终分配给您。 在路由器接口的左面板中,找到DHCP -> Address Reservation,单击它。输入计算机的MAC地址和您在代码中输入的IP地址。单击保存。这将为您的机器保留给定的IP地址。

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

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

我的工作(目标:调试运行在localhost:99999上的windows服务器应用程序,从运行在android手机上的客户端应用程序)

电话和电脑连接在同一网络上,例如192.168.1。XXX(在我的情况下通过wifi连接) 在Windows防火墙中开启99999端口 以管理员身份运行cmd: netsh http add urlacl url=http://*:99999/ user=Everyone

然后,可以从手机访问服务应用程序url (my_dev_machine_ip:99999/path_to_service)。

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

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地址的副本地址。右键单击您的网络->网络和共享->单击您当前拥有的连接->详细信息->然后ipv4地址旁边的地址是您的IP地址,请在某处注意这一点

进入控制面板->系统和安全-> windows防火墙->高级设置->入站规则->新规则(按照步骤添加端口,例如80,它真的很简单)

将您在手机浏览器中记下的IP地址和您为其创建规则的端口号放在旁边。例如192.168.0.2:80和wala。

可能的解决方案,如果它不连接。 右键点击网络->打开网络和共享->查看您的活动连接,在您的连接类型的名称下单击它,如果它是公共的,并确保将其更改为家庭网络。