title: Response for preflight has invalid HTTP status code 400
body: <p>I'm trying to make a REST call (POST) using AJAX. This is my AJAX code</p>
  
  <pre><code>&lt;script&gt;
  var settings = {
  "async": true,
  "crossDomain": true,
  "dataType": "json",
  "url": "http://localhost:port/service/myservice",
  "method": "POST",
  "data": '{jsondata}',
  "headers": {
        "accept": "application/json",
        "Authorization": "authValue"
    }
  }
  
  $.ajax(settings)
  
  .done(function (response) {
    console.log(response);
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Initially I got this error: <strong>XMLHttpRequest cannot load <a href="http://localhost:port/service/myservice" rel="nofollow">http://localhost:port/service/myservice</a>. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 400.</strong></p>
  
  <p>To resolve this issue I added the following code in my dropwizard application</p>
  
  <pre><code>Dynamic filter = env.servlets().addFilter("CORS", CrossOriginFilter.class);
  
  filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS");
  filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
      filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
  filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
  filter.setInitParameter("allowCredentials", "true");
  
  filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
  </code></pre>
  
  <p>After adding this my initial exception went away, but I'm getting the following exception: <strong>XMLHttpRequest cannot load <a href="http://localhost:port/service/myservice" rel="nofollow">http://localhost:port/service/myservice</a>. Response for preflight has invalid HTTP status code 400</strong></p>
  
  <p>Is this issue related to CORS? What am I doing wrong here?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After doing more debugging I found this behavior. When sending the request without the Authorization header I'm getting <strong>415 (Unsupported Media Type)</strong> error. </p>
  
  <p>I think something wrong with my AJAX code, can someone please help me find the issue? Thanks.</p>