Node.js 无法访问angular 10的内部版本中的数据头
下面是http请求中的我的代码头:Node.js 无法访问angular 10的内部版本中的数据头,node.js,angular,httprequest,httpresponse,Node.js,Angular,Httprequest,Httpresponse,下面是http请求中的我的代码头: return this.http.post<any>(this.path.userRoot + '/logIn/random', body, { withCredentials: true, responseType: "json", observe: 'response' } ) .pipe(
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;
}));
返回this.http.post(this.path.userRoot+'/logIn/random',body,
{
事实上,
响应类型:“json”,
观察:“回应”
}
)
.pipe(映射(响应=>{
如果(response.status==200){
localStorage.setItem('auth-token',response.headers.get('auth-token');
setItem('user',JSON.stringify(response.body.message));
this.userSubject.next(response.body.message);
}
返回响应;
}));
运行后,“response.headers.get('auth-token')”的值为null。
是否有办法解决此问题?如果使用CORS,则需要指定
访问控制公开标头(请参阅)服务器端
Access-Control-Expose-Headers: auth-token, OtherCustomHeader
你用的是cors吗?嗨,是的,我用的是一些后端代码。看起来你没有暴露标题。添加此标题后,问题就解决了,谢谢