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


当前回答

如果你使用mac (OSX):

在mac上:

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

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

在手机上:

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

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

其他回答

首先,你必须确认你也通过mac浏览器上的mac ip访问服务器api。 如果不是,请确保您的服务器允许这样做,而不仅仅是localhost(127.0.0.1),通过在0.0.0.0上运行您的服务器 去iphone上的safari,通过api你的服务器serve: ex http://0.0.0.0/st进行get请求。Safari自动重定向到服务器你的mac运行(在你的mac ip) 如果你想在你的iphone应用程序上发出请求,它应该用[你的mac/服务器ip]替换request 0.0.0.0

试试这个:

按Windows + R 打开cmd 执行命令ipconfig(旧)ifconfig(新) 检查你的无线网卡IP 打开iPhone,导航到“http://xxx.xxx.xxx”。Xxx /"通过浏览器。 (xxx.xxx.xxx。xxx是你的IP)

注意:你必须在你的防火墙设置上设置权限,如果有的话。

如果你正在做一个php项目,你可以改变href的基本值:

<基地href = " < ?php echo str_replace("localhost","192.x.x.x",HTTPS_SERVER);?”> >

Localhost或127.0.0.1:取决于您的设置 192. x.x。X:您的本地IP地址 HTTPS_SERVER:之前的base href

这样做对于在手机上加载图像、css和js文件至关重要。

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地址但仍然无法连接到本地服务器的人,另一件要检查的事情是您或您的同事没有将设备配置为使用代理服务器。

我有一台设备无法连接,结果发现该设备被配置为使用Charles Proxy,当然它没有运行。