下面是我在http请求中的代码头:
return this.http.post<any>(this.path.userRoot + '/logIn/random', body,
{
withCredentials: true,
responseType: "json",
observe: 'response'
}
)
.pipe(map(response => {
if (response.status === 200) {
localStorage.setItem('auth-token', response.headers.get('auth-token'));
localStorage.setItem('user', JSON.stringify(response.body.message));
this.userSubject.next(response.body.message);
}
return response;
}));运行后,"response.headers.get('auth-token')“的值为空。有没有办法解决这个问题?
发布于 2021-02-17 18:32:19
如果使用CORS,则需要指定Access-Control-Expose-Headers (请参阅documentation)服务器端。
Access-Control-Expose-Headers: auth-token, OtherCustomHeaderhttps://stackoverflow.com/questions/66239875
复制相似问题