简体   繁体   中英

Angular 5 HttpClient response headers does not contain custom headers

I have API made in Nodejs, after login i send the auth-token ( x-auth header) in the response on successful login.

When i hit the webservice from postman i am able to see the x-auth header but not in Angular 4

I am using HttpClient , not Http.

createClient(client:Client){
    return this.http.post(
      Config.baseUrl+'/client/login',client,{observe:'response'});
}

Then in my componenet

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);
    })

the data.headers.getAll('x-auth') returns Null.

Finally got it , it was not a issue with Angular , but with my Node app

Had to add middleware to expose the headers to the client.

res.header("access-control-expose-headers",
    ",x-auth"
    +",Content-Length"
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM