【问题标题】:Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid错误请求 - 无效主机名 HTTP 错误 400。请求主机名无效
【发布时间】:2019-05-10 09:48:55
【问题描述】:

我收到此错误:

Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid

在使用 https 的全新网站上。

我的绑定如下所示:

我也尝试将test.example.com* 作为我的主机名。

我正在使用从 GoDaddy 获得并使用其中一种在线验证服务进行验证的证书(安装后)。

我已经追了几个小时这个错误,快要发疯了。其他人正在报告此错误,但他们在 http 或 IIS7 上报告此错误。我在 IIS10 上,所以 IIS7 解决方案不适用。

我在 Amazon EC2 上。

我怀疑以下问题,但我不知道如何解决:

不知何故,我必须告诉与我的证书 (test.example.com) 同名的机器 (EC2AMAZ-XYZ)。

这个命令可以正常运行:

curl https://test.example.com:8028

但是这个命令会因为上面的错误而失败:

curl -d '{"UserName":"JOHN", "Password":"CHANGEME"}' -H "Content-Type: application/json" -X POST https://test.example.com:8028/api/Account/login

如果我在浏览器中使用https://test.example.com:8028,它可以正常工作,但是我无法在浏览器中运行 POST 命令。

我们添加了一个基于 GET 的登录版本,但它失败并出现同样的错误。我们还启用了http,它也失败了。

这里是与这个问题相关的代码:

using System.Web.Http;
using Newtonsoft.Json.Serialization;

namespace TappDmz
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();
            // Route to index.html
            config.Routes.MapHttpRoute(
                name: "Index",
                routeTemplate: "{id}.html",
                defaults: new { id = "index" });

            config.Routes.MapHttpRoute(
             name: "DefaultApi",
             routeTemplate: "api/{controller}/{id}",
             defaults: new { id = RouteParameter.Optional });
            //Now set the serializer setting for JsonFormatter to Indented to get Json Formatted data  
            config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
            //For converting data in Camel Case  
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        }
    }
}

【问题讨论】:

标签: ssl curl iis-10


【解决方案1】:

命令行curl 难以确定您要连接的主机。试试这个

curl -H 'Host: test.example.com' -d '{"UserName":"JOHN", "Password":"CHANGEME"}' -H "Content-Type: application/json" -X POST https://test.example.com:8028/api/Account/login

here

【讨论】:

  • 按照这些思路:我是否需要告诉 EC2 机器的名称以便某种反向查找起作用?现在它具有编码的 AWS 名称。我用我的名字用 DNS 指向它,但亚马逊不知道。
猜你喜欢
  • 2015-08-17
  • 2019-11-30
  • 1970-01-01
  • 2016-10-20
  • 1970-01-01
  • 2014-12-11
  • 2017-08-26
  • 2019-03-27
  • 2016-12-12
相关资源
最近更新 更多