首页 文章

错误请求 - 无效主机名HTTP错误400.请求主机名无效

提问于
浏览
0

我收到此错误:

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

在使用https的全新网站上 .

我的绑定看起来像这样:

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

我使用的是从GoDaddy获得的证书,并使用其中一个在线验证服务进行验证(安装后) .

我一直在追逐这个错误几个小时,并且即将疯狂 . 其他人报告此错误,但他们在http或IIS7上报告 . 我在IIS10上,所以IIS7解决方案不适用 .

我在Amazon EC2上 .

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

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

这个命令运行正常:

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的Login版本,它失败并出现相同的错误 . 我们也启用了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();
        }
    }
}

1 回答

  • 0

    命令行 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

相关问题