[英]Angular 5 HttpClient response headers does not contain custom headers
我在Nodejs中创建了API,登录后我在成功登录时在响应中发送了auth-token( x-auth
头)。
当我从邮递员点击web服务时,我能够看到x-auth
标头,但不能在Angular 4中看到
我使用的是HttpClient,而不是Http。
createClient(client:Client){
return this.http.post(
Config.baseUrl+'/client/login',client,{observe:'response'});
}
然后在我的组件中
this.userService.createClient(this.signupForm.value).subscribe((data)=>{
this.clientCreatedSuccessfully = true;
console.log(data);
console.log(data.headers.getAll('x-auth'));
},(error)=>{
this.clientExist = true;
console.log(error);
})
data.headers.getAll('x-auth')
返回Null。
终于搞定了,这不是Angular的问题,而是我的Node应用程序
必须添加中间件以将标头暴露给客户端。
res.header("access-control-expose-headers",
",x-auth"
+",Content-Length"
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.