Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法访问angular 10的内部版本中的数据头_Node.js_Angular_Httprequest_Httpresponse - Fatal编程技术网

Node.js 无法访问angular 10的内部版本中的数据头

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(

下面是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;
        }));
返回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吗?嗨,是的,我用的是一些后端代码。看起来你没有暴露标题。添加此标题后,问题就解决了,谢谢