HttpClient订阅的响应标头未定义

时间:2018-03-26 17:18:55

标签: node.js angular rest observable

任何人都可以告诉我为什么在从http.post收到回复时我没有收到任何标题?

this.http.post<Response>(url, body).subscribe((res: Response) => console.log(res.headers));

res.headers记录'undefined',但是在Chrome DevTools中,响应显示了我正在寻找的标题。

附注:我确实将Access-Control-Expose-Headers设置为我想要公开的标题。

知道为什么会这样吗?

2 个答案:

答案 0 :(得分:5)

观察响应而不是类型化的身体,默认情况下较新的HttpClient会执行此操作:

this.http.post(url, data, {observe: 'response'}).subscribe((res:Response) => {});

IE中。您正在做的只是将服务器发送的数据类型转换为<Response>

答案 1 :(得分:-1)

Just import Response from `@angular/http` or `@angular/common/http`
reference official doc : https://angular.io/guide/http
                         https://alligator.io/angular/angular-5/
                         https://blog.angular.io/version-5-0-0-of-angular-now-available-37e414935ced
相关问题