我有一个Spring Boot服务器,该服务器使用身份验证过滤器返回称为“ Autorization”的JWT标头。 我的JS反应应用程序使用获取响应的“获取”方法来使用此登录调用(CORS)。 我已经知道有标准的响应标头,并且Authorization不是其中之一,因此我使服务器返回Access-Control-Allow-Headers:Authorization,以及 授权标头本身:
我可以在浏览器开发工具上看到标头返回,但是在JS中却没有:
return fetch(url, {
headers,
...options
})
.then(this._checkStatus)
.then(response => {
//response.json()
const headers = response.headers.entries();
let header = headers.next();
while (!header.done){
console.log(header.value);
header = header.next();
}
return {id_token : response.headers.get('Authorization')};
})
“授权”未打印。
响应头:
Access-Control-Allow-Headers: authorization
Access-Control-Allow-Origin: *
Authorization: Bearer eyJ0eXAi....ewlsTNGyg
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Length: 0
Date: Mon, 13 Apr 2020 06:33:46 GMT
Expires: 0
Pragma: no-cache
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
控制台打印:
cache-control: no-cache, no-store, max-age=0, must-revalidate
AuthService.js:82 content-length: 0
AuthService.js:82 expires: 0
AuthService.js:82 pragma: no-cache
尝试访问控制允许标题:使用或不使用大写字母“ A”的授权。