title: Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid
body: <p>I am getting this error:</p>
  
  <pre><code>Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid
  </code></pre>
  
  <p>On a brand new site that is using https.</p>
  
  <p>My bindings look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/eOvG3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eOvG3.png" alt="enter image description here"></a></p>
  
  <p>I tried <code>test.example.com</code> and <code>*</code> as my hostname as well.</p>
  
  <p>I am using a certificate that I got from GoDaddy and validated using one of those online validation services (after installation).</p>
  
  <p>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.</p>
  
  <p>I am on Amazon EC2.</p>
  
  <p>I suspect the following problem but I don't know how to fix it:</p>
  
  <p>Somehow I have to tell the machine (EC2AMAZ-XYZ) that has the same name as my certificate (test.example.com).</p>
  
  <p>This command will run fine:</p>
  
  <pre><code>curl https://test.example.com:8028
  </code></pre>
  
  <p>But this command will fail with the above error:</p>
  
  <pre><code>curl -d '{"UserName":"JOHN", "Password":"CHANGEME"}' -H "Content-Type: application/json" -X POST https://test.example.com:8028/api/Account/login
  </code></pre>
  
  <p>If I use <code>https://test.example.com:8028</code> in a browser it works fine, but the I can't run the POST command in a browser.</p>
  
  <p>We added a GET based version of Login and it fails with same error.  We also enabled http and it also fails.</p>
  
  <p>Here is the code related to this problem:</p>
  
  <pre><code>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();
          }
      }
  }
  </code></pre>