[英]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.