首页 > 解决方案 > 从 Angular 8 访问公开的标头

问题描述

我正在尝试使用角度 8 从后端获取暴露的标头。在这里您可以在我发布 API 时看到响应标头

**Response headers(6)**
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:4200
Access-Control-Expose-Headers: Xtoken, CX-Token, Content-Disposition
Content-Length: 0
Date: Mon, 07 Oct 2019 09:03:34 GMT
Vary: Origin

我想访问Xtoken

login(login: string, password: string) {
        return this.http.post<any>(`${apiUrl.apiUrl}//login`, { login, password }, { observe: 'response' as 'body' })
            .pipe(map((res, err) => {
                console.log(res.headers.get("Xtoken"));

            }));
    }

它返回null

有人可以帮忙吗?

标签: angularhttp-headers

解决方案


推荐阅读