错误的请求 - 通过手机的 wifi 连接到本地主机时主机名无效 [英] Bad Request- Invalid Hostname while connect to localhost via wifi from mobile phone

查看:102
本文介绍了错误的请求 - 通过手机的 wifi 连接到本地主机时主机名无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试连接笔记本电脑的本地主机时收到错误请求 - 无效主机名 [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防火墙的入站规则

  1. 打开高级安全 Windows 防火墙.
  2. 在左侧面板中,右键单击入站规则 > 新建规则
  3. 规则类型:端口
    协议和端口:TCP
    特定的本地端口:57976
    操作:允许连接
    个人资料:勾选所有(域、私人、公共)
    名称:名称、说明(可选)
  4. 完成.

  1. Open the Windows Firewall with Advanced Security.
  2. At the left panel, right click on Inbound Rule > New Rule
  3. 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)
  4. Finish.

第 2 步:IIS 或 IIS Express

添加IIS管理器绑定

  1. 打开IIS 管理器.
  2. 在左侧面板中,转到站点 > 默认网站.
  3. 在右侧面板中,单击绑定.然后,弹出新对话框.
  4. 在弹出对话框中,单击添加"按钮.输入端口号和主机名.
    就我而言,
    端口 = 57976;
    主机名 = 192.XXX.XXX.XXX(我的IP地址)

  1. Open the IIS Manager.
  2. At the left panel, Go to Sites > Default Web Sites.
  3. At the right panel, click on the Bindings. Then, the new dialog pop ups.
  4. 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) 的绑定

  1. 停止当前站点
  2. 对于 Visual Studio 2015,更改项目文件夹 C:Projects.vsconfigapplicationhost.config‌ 下的 IIS 配置.
  3. 对于以前版本的 Visual Studio 2015,更改 IIS Express 文件夹下的 IIS 配置C:UsersDocumentsIISExpressconfigapplicationhost.config
  4. applicationhost.config中,搜索端口号(我的例子是57976),然后再绑定你的IP地址

  1. Stop the current Site
  2. For Visual Studio 2015, change the IIS config under your project folder C:Projects<ProjectName>.vsconfigapplicationhost.config‌​.
  3. For previous version of Visual Studio 2015, change the IIS config under IIS Express folder C:Users<your profile name>DocumentsIISExpressconfigapplicationhost.config
  4. 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

解决方案:

  1. 关闭 Visual Studio
  2. 右键单击 Visual Studio > 运行方式管理员



参考:https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-how-to-configure-iis-express/

这篇关于错误的请求 - 通过手机的 wifi 连接到本地主机时主机名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆