【发布时间】: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();
}
}
}
【问题讨论】:
-
也发布这个或分享这个 SO 链接到aws.amazon.com/developer/community
-
如果您使用IE/Chrome等网络浏览器会出现什么错误?
-
Lex Li:这个“curl test.example.com:8028”命令说它在网络浏览器上运行良好。
-
@Softhmak。我更喜欢 Swagger en.wikipedia.org/wiki/Swagger_(software)
-
@Michael Potter 您能否将
-v添加到您的 curl 命令并将输出粘贴到您的问题中?