Angular $ http: pre-flight response has an invalid 403 HTTP status code

I am writing an angular application and I am trying to connect to our API using a service $http.

$http.post('https://backend-test/***/v001/login', {'userName': 'admin', 'password': 'passtest'}, {headers: {'Accept': 'application/json', 'Content-Type': 'application/json'}}).then(function success(response) {
    console.log(response);
});

However, I keep getting this error:

XMLHttpRequest cannot load https: // backend-test / *** / v001 / login. response for pre-flight has an invalid HTTP status code 403

An OPTIONS request is also presented instead of a POST request:

Request Method: OPTIONS

It is strange that it works correctly when I use this tool:

https://www.hurl.it/

Any thoughts?

+4
source share
2 answers

. - tomcat. , web.xml :

<filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    <init-param>
        <param-name>cors.allowed.headers</param-name>
        <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization</param-value>
    </init-param>     
</filter>
+4

Cors exressJS (NodeJS)

npm install cors

:

var cors = require('cors'),express = require('express');
var app = express(); // defining app using express

app.use(cors()); // **core as middleware**
+1

Source: https://habr.com/ru/post/1614807/


All Articles