该应用程序有一个外部身份验证过程,在从外部系统成功验证用户身份后,用户将被重定向到我的应用程序,并带有 header 值,那么如何在 Angular8 应用程序中读取这些 header 值。
在应用程序模块和应用程序组件承包商方法中使用了 HttpClientModule,但没有成功,并在所述类中使用了 HttpHeaders
最佳答案
这就是你缺少的部分=> , {observe: 'response'}
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);
});
Angular 4.3.3 HttpClient : How get value from the header of a response?
关于javascript - 如何访问 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57883828/