I have an angular client application which is loaded in asp net core. The initial request which comes from asp net core to angular app gives a few headers , How can i capture those headers in angular to reuse them later. I am able to capture headers or intercept calls which are made by angular , how can i capture header from initial response. Please suggest.
Asked
Active
Viewed 78 times
1 Answers
0
Example of GET headers
http
.get<MyJsonData>('/data.json', {observe: 'response'})
.subscribe(resp => {
// Here, resp is of type HttpResponse<MyJsonData>.
// You can inspect its headers:
console.log(resp.headers.get('X-Custom-Header'));
// And access the body directly, which is typed as MyJsonData as requested.
console.log(resp.body.someField);
});
example of POST with headers
http
.post('/api/items/add', body, {
headers: new HttpHeaders().set('Authorization', 'my-auth-token'),
})
.subscribe();
The HttpHeaders class is immutable, so every set() returns a new instance and applies the changes.
More details https://angular.io/guide/http
Edit: I am not sure what do you mean by using them later - perhaps you can save them to SessionStorage or LocalStorage if you need them after refreshing the page.
Check this also: Accessing the web page's HTTP Headers in JavaScript might help

DrNio
- 1,936
- 1
- 19
- 25