Fetch API can not load [URL]. Response for preflight has invalid HTTP status code 404

2

Greetings!

I am facing the following problem, I make a request [POST] via Fetch API and "call" does not complete.

REQUEST VIA Fetch API

const requestInfo = {
    method: 'POST',
    body: JSON.stringify({ email:'[email protected]' , password:'123456', entity:'provider'}),
    headers: new Headers({'Content-type': 'application/json;charset=UTF-8'}),
};
fetch('http://localhost:4212/login',requestInfo)
    .then(response => {
        console.log(response);
        return response.json();
    })
    .then(sucess => console.log(sucess))
    .catch(error => console.log(error));
    }

RESPONSE VIA Fetch API

Thestrangethingisthat[GET]typefunctionworksperfectly.

VIAPOSTMANREQUIREMENT

Viapostmanalsoworks[GET/POST].

HEADERS DELIVERED

access-control-allow-credentials →true
access-control-allow-headers →Origin, X-Requested-With, Content-Type, Accept, Accept-Encoding, Content-Encoding, X-Auth-Token
access-control-allow-methods →POST, GET, PUT, OPTIONS, DELETE, PATCH
access-control-allow-origin →*
access-control-max-age →3600
cache-control →no-cache, no-store, max-age=0, must-revalidate
content-encoding →gzip
content-type →application/json;charset=UTF-8
date →Thu, 27 Jul 2017 02:14:50 GMT
expires →0
pragma →no-cache
transfer-encoding →chunked
vary →Accept-Encoding
x-content-type-options →nosniff
x-frame-options →DENY
x-xss-protection →1; mode=block

Do you know what it can be?

Thank you!

    
asked by anonymous 27.07.2017 / 04:24

2 answers

1

Thanks for the attention

I solved the problem by adding this line in the color settings.

.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()

If I declare only POST / PUT does not work. I have to learn more to discover. vlw

    
28.07.2017 / 02:49
2

Many times, Postman will work because the rules of "Cross Origin Requests" do not apply. If you are using Express.js, you can use this:

link

The problem is that your server does not accept requests from a different source. Use cors to allow your client to access your server.

    
27.07.2017 / 09:47