我的功能如下:
testFunctionAuth() {
const promise = new Promise((resolve, reject) => {
this.http.get(AppConfigService.settings.apiServer.rest + 'systems/all', { headers: { 'Authorization': 'Bearer eyJ...rxbwcO-w' } })
.subscribe(res => {
resolve(res);
},
err => {
console.error(err);
reject(undefined);
});
});
}
但是我得到了401,并且在标头中,甚至还没有Auth令牌:
根据HTTP规范,在没有身份验证标头的情况下执行OPTIONS请求。]但是您的后端似乎在验证用户凭据。
来自https://stackoverflow.com/a/40723041:
根据CORS specification when a preflight request为执行的用户凭据被排除。
((...)使用方法OPTIONS,并具有以下附加约束:
- (...)
- 排除作者请求标头。
- 排除用户凭据。
- (...)
(重点是我的)
考虑到这一点,问题似乎出在API方面,哪个应该接受
。OPTIONS
请求而无需身份验证