Response for preflight has invalid HTTP status code 401 - Spring
<p>everyone.
I'm new to Angular 2 and Spring Framework.
I'm trying a simple get request with an authorization header (basic auth).</p>

<p>I'm using Spring Boot (1.2.6.RELEASE), which can also be relevant.
My CORS configuration looks like this.</p>

<pre><code>@Component
public class SimpleCorsFilter implements Filter {

private final Logger log = LoggerFactory.getLogger(SimpleCorsFilter.class);

public SimpleCorsFilter() {
    log.info("SimpleCORSFilter init");
}

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
    response.setHeader("Access-Control-Allow-Credentials", "true");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me, authorization, x-auth-token");

    chain.doFilter(req, res);
}

@Override
public void init(FilterConfig filterConfig) {
}

@Override
public void destroy() {
}

}
</code></pre>

<p>And here's what it looks like from the client side</p>

<pre><code>    this.headers.append('Authorization', 'Basic dXNlcjphZG1pbg==');
    return this.http
            .get(`http://localhost:8080/api/login?username=${username}`, {headers : this.headers} )
            .map(response =&gt; response.json().data as any);
}
</code></pre>

<p>I keep getting:</p>

<blockquote>
  <p>XMLHttpRequest cannot load
  <a href="http://localhost:8080/api/login?username=user" rel="noreferrer">http://localhost:8080/api/login?username=user</a>. Response for preflight
  has invalid HTTP status code 401</p>
</blockquote>

<p>Please help, i don't know what i'm missing...
I checked around a lot of posts already but couldn't get there...</p>