I try to get the headers from a http response if the error code is 401 for the digest auth.
This is my code:
this.http.post(this.hostname + ':10000/users/auth2', { })
.subscribe(res => {
console.log(res);
},
error => {
console.log(error);
});
Everything work's fine if the post request return a 200 code. If I return a 401 code from the backend I cannot access the headers.
The chrome debugger shows the headers. Postman call also work's fine with digest auth.
The default option for observe parameter is body, change it by
adding {observe: 'response'} to your post method:
this.http.post(this.hostname + ':10000/users/auth2', {}, {observe: 'response'})
.subscribe(res => {
console.log(res);
},
error => {
console.log(error.headers);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With