我正在做一个移动网站,想用我的iPhone浏览器测试一下。我的Windows 7电脑和iPhone都在同一个无线网络上。如何从iPhone访问localhost ?现在我得到一个404错误。


当前回答

For Mac users, open up the Network Utility (You can find this by typing cmd + space which will open spotlight and then in spotlight start typing Network Utility). Select Network Utility, when it's open, your IP address will be found next to the label IP Address. So basically with the IP, you can get into any open ports on your local mac e.g. if your website is running locally on localhost:3000 and your ip address is 154.31.92.0 then from your phone you can get the website simply by typing 154.31.92.0:3000 into a browser.

PS-这只适用于手机和电脑在同一个网络上

其他回答

找到你系统的IP地址和你运行网站的端口。

假设您的IP地址是121.300.00.250,端口是8080。

[端口号:在运行页面时看到您的web浏览器,例如:localhost:8080/…]那么端口号是8080]

现在在你的手机转到121.300.00.250:8080/..你会找到你的网站。

重要提示:您必须确保您的服务器(例如Apache Tomcat)处于启动状态

如果您正在使用MAMP,在您的iPhone Safari浏览器中输入您的IP地址(例如192.0.0.63),然后输入端口号8888(例如192.0.63:8888),您将能够在您的iPhone中看到您的本地站点。

如果使用WAMP服务器,同样在iPhone safari浏览器中输入IP地址(比如192.0.0.63),就是这样。但是不要忘记从WAMP服务器的httpd.conf文件中删除deny。如果你从127.0.0.1开始查找allow线,在它上面或下面,你会看到deny from all;只需要删除这一行并重新启动WAMP服务器就可以了。

如果你用的是Mac -

通过USB连接你的iPhone和Mac。 进入Network Utility (cmd+空格,输入“Network Utility”) 进入“信息”选项卡 点击显示“Wi-Fi”的下拉菜单,如图所示选择“iPhone USB”。

你会发现一个类似“xxx.xxx.xx”的IP地址。或者类似的。打开iPhone的Safari浏览器,输入IP_address:port_number 例如:169.254.72.86:3000

[注意:如果IP地址字段为空,请确保您的iPhone通过USB连接,退出网络实用程序,重新打开并检查IP地址。]

警告:自macOS大苏尔以来,网络实用程序已弃用。

如果你使用Mac,进入系统首选项>网络,使用你的IP地址而不是本地主机。您也可以使用端口号。在我的例子中,我有一个在端口1448上运行的服务器,我可以使用iPhone预览192.168.1.241:1448。

如果你使用mac (OSX):

在mac上:

打开终端 运行“ifconfig” 找到ip地址为“192.xx.x.x”的行

如果你用地址测试你的网站:"localhost:8888/mywebsite"(这取决于你的MAMP配置)

在手机上:

打开浏览器(如Safari) 输入URL 192.xx . x.x.x:8888/mywebsite

注意:必须连接在同一网络(wifi)