我可以使用Android模拟器访问我的笔记本电脑web服务器,我使用10.0.2.2:portno 工作得很好。
但当我连接真正的Android手机时,手机浏览器无法连接到我笔记本电脑上的同一个web服务器。手机和笔记本电脑通过USB线连接。如果我运行 adb devices命令,我可以看到我的手机。
我错过了什么?
我可以使用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.
其他回答
在Windows PC上,您可能不需要做任何其他事情,只需使用“ipconfig”命令查找您的IPv4地址。
第一步:用USB线连接你的手机和电脑。 第二步:使用命令'ipconfig'找到你的IPv4地址(路由器的外部IP),例如192.168.1.5。 步骤3:只需从手机浏览器中访问“192.168.1.5:8080”。真的有用!
其他环境细节: Windows 7,谷歌Nexus 4 (4.2.2), Tomcat服务器,Grails应用程序。
你还应该确保你在AndroidManifest文件中有访问internet的权限:
<uses-permission android:name="android.permission.INTERNET"/>
“Chrome for Android的端口转发让你更容易在手机上测试你的开发站点。它的工作原理是在移动设备上创建一个监听TCP端口,该端口映射到开发机器上的特定TCP端口。这些端口之间的流量通过USB传输,因此连接不依赖于你的网络配置。”
更多详情请访问:https://developer.chrome.com/devtools/docs/remote-debugging#port-forwarding
即使您的移动设备和电脑通过usb连接,此解决方案也可用:
此时需要使用端口转发功能。 在谷歌chrome inspect窗口(chrome://inspect)可以看到连接的设备。
点击端口fowading按钮,并设置一个随机端口,例如3000到您的笔记本电脑使用的端口,例如8080。
现在从设备上使用localhost:3000来访问笔记本电脑中的localhost:8080(or_whatever_ip:portno)。 您可以在移动浏览器中查看。在移动浏览器中尝试localhost:3000。 确保勾选“端口转发设置”窗口中的“启用端口转发”复选框
我的工作(目标:调试运行在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)。
这对我来说是有用的,我在127.0.0.1 ip后添加了另一行,以指定我想使用的设备的确切本地网络ip地址(而不是公共ip地址)。我用的是三星Galaxy S3
根据Bangptit的建议,编辑httpd.conf文件(x是版本号): C: \ wamp \ bin \ apache \ Apache2.x.x \ conf \ httpd . conf
搜索onlineoffline标签,并添加您的电话的ip(我发现我的电话ip地址在我的路由器配置页面):
Onlineoffline标签-不要删除
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
我的电话IP在下面一行
Allow from 192.168.1.65
Allow from ::1
Allow from localhost
可以将其扩展到包括整个子域,例如192.168.1.0/24等