I am getting this error:
Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid
On a brand new site that is using https.
My bindings look like this:
I tried test.example.com
and *
as my hostname as well.
I am using a certificate that I got from GoDaddy and validated using one of those online validation services (after installation).
I have been chasing this error for several hours and about to go crazy. Other people are reporting this error but they are reporting it on http or IIS7. I am on IIS10 so the IIS7 solutions don't apply.
I am on Amazon EC2.
I suspect the following problem but I don't know how to fix it:
Somehow I have to tell the machine (EC2AMAZ-XYZ) that has the same name as my certificate (test.example.com).
This command will run fine:
curl https://test.example.com:8028
But this command will fail with the above error:
curl -d '{"UserName":"JOHN", "Password":"CHANGEME"}' -H "Content-Type: application/json" -X POST https://test.example.com:8028/api/Account/login
If I use https://test.example.com:8028
in a browser it works fine, but the I can't run the POST command in a browser.
We added a GET based version of Login and it fails with same error. We also enabled http and it also fails.
Here is the code related to this problem:
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();
}
}
}