错误请求 - 通过wifi从手机连接到localhost时无效的主机名 [英] Bad Request- Invalid Hostname while connect to localhost via wifi from mobile phone
问题描述
尝试连接笔记本电脑的localhost时,我收到错误请求 - 无效主机名[HTTP ERROR 400] 。
实际上,我正在学习使用jQuery Mobile开发移动网络。
我想看看网络的布局是否适合我的手机尺寸。
I get the Bad Request- Invalid Hostname [HTTP ERROR 400] while trying connect my laptop's localhost. Actually, I am learning to develop mobile web using jQuery Mobile. I want to see the layout of the web whether fit my phone size.
我添加了Visual Studio以这种方式给出的端口号:
控制面板>防火墙>高级设置>退回规则>新规则。
然后,我输入 ipconfig <获取我的IP地址/ strong>在命令提示符下。
之后,我使用我的Android手机浏览器(Mozilla 5.0)并输入链接192.XXX.XXX.XXX:57976。
i have added the port number which given by the Visual Studio with this way:
Control Panel> Firewall> Advanced Settings> Inbounce Rules> New Rule.
Then, i get my IP address by typing "ipconfig" at Command Prompt.
After that, I use my Android phone browser (Mozilla 5.0) and enter the link 192.XXX.XXX.XXX:57976.
I我读过类似的问题,但我无法得到解决方案。
有些人认为此错误与IIS设置有关。
但我无法获得IIS设置的解决方案。
希望你们能帮助我解决这个问题。
I have read similar questions but I can't get the solution. Some people think this error is related to the IIS settings. But I can't get the solution of the IIS settings. Hope you guys can help me solve this problem.
推荐答案
步骤1:添加Windows防火墙的入站规则
Step 1: Add Inbound Rule of Windows Firewall
- 打开 Windows具有高级安全性的防火墙。
- 在左侧面板中,右键单击入站规则> 新规则
- 规则类型:端口
协议和端口:TCP
具体本地端口:57976
操作:允许连接
个人资料:全部勾选(域名,私人,公开)
姓名:姓名,说明(可选)
- 完成。
- Open the Windows Firewall with Advanced Security.
- At the left panel, right click on Inbound Rule > New Rule
- Rule Type: Port
Protocol and Ports: TCP
Specific local ports: 57976
Action: Allow the connection
Profile: Tick all (Domain, Private, Public)
Name: Name, Description(optional) - Finish.
第2步:IIS或IIS Express
添加IIS管理器的绑定
- 打开 IIS管理器。
- 在左侧面板中,转到网站> 默认网站。
- 在右侧面板中,单击绑定。然后,弹出新对话框。
- 在弹出对话框中,单击添加按钮。输入端口号和主机名。
对于我的情况,
端口 = 57976;
主机名 = 192.XXX.XXX.XXX(我的IP地址)
- Open the IIS Manager.
- At the left panel, Go to Sites > Default Web Sites.
- At the right panel, click on the Bindings. Then, the new dialog pop ups.
- At the pop-up dialog, click on the "Add" buttons. Input the port number and the hostname.
For my case,
port = 57976;
hostname = 192.XXX.XXX.XXX (my IP address)
添加IIS Express的绑定(Visual Studio)
- 停止当前站点
- 对于 Visual Studio 2015 ,更改IIS配置在您的项目文件夹
C:\Projects \< ProjectName> \.vs \config\applicationhost.config
。 - 对于以前版本的Visual Studio 2015 ,请更改IIS Express文件夹下的IIS配置
C:\Users \<您的个人资料名称> \文档\ IISExpress\config\applicationhost.config
-
在
应用程序中ionhost.config
,按端口号搜索(我的情况是57976),然后再绑定一个你的IP地址
- Stop the current Site
- For Visual Studio 2015, change the IIS config under your project folder
C:\Projects\<ProjectName>\.vs\config\applicationhost.config
. - For previous version of Visual Studio 2015, change the IIS config under IIS Express folder
C:\Users\<your profile name>\Documents\IISExpress\config\applicationhost.config
In
applicationhost.config
, search by the port number (for my case is 57976), then one more binding with your IP Address
<site name="Web(1)" id="9">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\abc\project\dev\web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:57976:localhost" />
<binding protocol="http" bindingInformation="*:57976:192.XXX.X.XXX" />
</bindings>
</site>
更新:
对于Windows 10或Visual Studio 2015用户,
您可能会收到以下错误消息:
Updated:
For windows 10 or Visual Studio 2015 users, you may get the error message below:
Unable to launch the IIS Express Web server, Failed to register URL, Access is denied
解决方案:
- 关闭Visual Studio
- 右键单击Visual Studio>以
管理员身份运行
这篇关于错误请求 - 通过wifi从手机连接到localhost时无效的主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!