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

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

我错过了什么?


当前回答

默认localhost的更简单方法是使用http://localhost:port。这也适用于笔记本电脑和安卓系统。

如果它不工作,然后在android设置您的手机的默认IP 127.0.0.1:端口:)

打开终端并输入:-

 hostname -i
 #127.0.0.1
 hostname -I
 #198.168.*.*

其他回答

这些回答中没有一个提到从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.

基于笔记本电脑的移动设备连接wamp服务器的解决方案:

首先,wifi不是路由器。因此,为了将我的移动设备连接到我笔记本电脑上基于localhost的wamp服务器,我需要一个路由器。 我下载并安装了一个免费的虚拟路由器:https://virtualrouter.codeplex.com/

配置它真的很简单:

右键单击系统托盘中的虚拟路由器图标 2 .单击“配置虚拟路由器” 填写密码 如果您的internet连接是以太网,请选择共享连接:以太网 然后在你的笔记本电脑和设备上打开wifi 在您的设备上连接到虚拟路由器网络名

然后你可以通过你的设备连接到你的笔记本电脑,启动浏览器并填写你的笔记本电脑的IPV4地址 (要在windows上找到它,键入CMD: ipconfig,并找到ipv4地址)

您应该看到wamp服务器主页。

Windows解决方案:

你无法浏览你的网站,主要是因为你的防火墙( 默认操作系统防火墙或防病毒防火墙)正在阻止传入 连接。

Windows防火墙下:

要允许特定端口上的传入连接,请转到:

控制面板> Windows防御防火墙>高级设置>右侧 单击“入站规则>添加新规则”。 然后: 选择“端口”单选按钮。 输入要在其上启用传入连接的特定端口/范围(服务器正在运行的端口) 选择“允许连接”单选按钮。 单击Next(除非您想更改默认值) 给规则起个名字,然后单击Finish。

注意:

如果您正在使用带有防火墙的防病毒软件,那么上述步骤将不起作用,因为防病毒软件将禁用Windows防火墙,而是运行自己的防火墙。

在这种情况下,根据防病毒程序,转到您的防病毒防火墙设置并打开端口。

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

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.

事情就是这么简单。

我使用了这个过程:

在PC上安装Fiddler 按照这些优秀的说明设置PC和Android设备 只需在Android设备上打开浏览器,输入http://ipv4.fiddler访问本地主机

注意,这个过程需要你在每次会话开始和结束时更改Android设备上的WiFi设置。我发现这比我的Android设备更轻松。