Angular 8 httpclient 响应标头对于 POST 方法为空



我已经从后端启用了Access-Control-Expose-Headers。但是仍然在角度8 http客户端POST方法调用中,响应标头为空。

它总是显示

HttpResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:8080/rest/auth/login", ok: true, …}
headers: HttpHeaders
normalizedNames: Map(0)
[[Entries]]
No properties
size: (...)
__proto__: Map
lazyUpdate: null
lazyInit: () => {…}
__proto__: Object
status: 200
statusText: "OK"
url: "http://localhost:8080/rest/auth/login"
ok: true

在发送请求的 Angular 应用中,传递一个对象{observe: 'response'}

http
.post<any>('url', {observe: 'response'})
.subscribe(response => {
console.log(response.headers.get('x-auth-token'));
});

最新更新