Fetch API: Cannot add authorization in request header with Chrome

Chrome Version : 57.0.2987

Actually, in the old version of Chrome, I also have this problem. I added Authorizationin the request header with my access token,

fetch('https://example.com/endpoint', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer ' + accesstoken
  }  
})

I always get Access-Control-Allow-Headers:authorizationin the Response Header in Chrome In addition, My fetch is always by request: OPTIONS (not displayed GET), and then Status Code- with a 200 OK in Chrome

But if I run the same extraction code in Firefox (ver 52.0.1), everything works fine. I can add Authorizationa title to the header correctly. He does not display Access-Control-Allow-Headers:authorizationin the Response header in Firefox. It will display Authorization: Bearer accesstokenin the request header.

CORS .

Chrome ? , Authorization Chrome?

Chrome. Below is the detailed network information in the Chrome dev tool:

Firefox: enter image description here

+4
2

@stackdave, OPTIONS GET ajax. . , , OPTIONS. , CORS, api .

0

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


All Articles