【发布时间】:2021-02-17 10:15:50
【问题描述】:
这里是我在 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')”的值为空。 有没有办法解决这个问题?
【问题讨论】:
-
你用的是cors吗?
-
嗨,是的,我用它
-
显示一些后端代码。看起来你没有公开标题
-
是的,添加此标题后解决,谢谢
标签: node.js angular httprequest httpresponse