错误的请求 - 通过手机的 wifi 连接到本地主机时主机名无效 [英] Bad Request- Invalid Hostname while connect to localhost via wifi from mobile phone
问题描述
我在尝试连接笔记本电脑的本地主机时收到错误请求 - 无效主机名 [HTTP 错误 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 地址.
之后,我使用我的 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.
我已经阅读过类似的问题,但我无法找到解决方案.有些人认为此错误与 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.
推荐答案
第一步:添加Windows防火墙的入站规则
- 打开高级安全 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,更改项目文件夹
C:Projects
下的 IIS 配置..vsconfigapplicationhost.config - 对于以前版本的 Visual Studio 2015,更改 IIS Express 文件夹下的 IIS 配置
C:Users
DocumentsIISExpressconfigapplicationhost.config 在
applicationhost.config
中,搜索端口号(我的例子是57976),然后再绑定你的IP地址
- Stop the current Site
- For Visual Studio 2015, change the IIS config under your project folder
C:Projects<ProjectName>.vsconfigapplicationhost.config
. - For previous version of Visual Studio 2015, change the IIS config under IIS Express folder
C:Users<your profile name>DocumentsIISExpressconfigapplicationhost.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:abcprojectdevweb" />
</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 连接到本地主机时主机名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!