首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法访问angular 10的内部版本中的数据头

无法访问angular 10的内部版本中的数据头
EN

Stack Overflow用户
提问于 2021-02-17 18:15:50
回答 1查看 18关注 0票数 0

下面是我在http请求中的代码头:

代码语言:javascript
复制
    return this.http.post<any>(this.path.userRoot + '/logIn/random', body,
        {
            withCredentials: true,
            responseType: "json",
            observe: 'response'
        }
    )
        .pipe(map(response => {
            if (response.status === 200) {
                localStorage.setItem('auth-token', response.headers.get('auth-token'));
                localStorage.setItem('user', JSON.stringify(response.body.message));
                this.userSubject.next(response.body.message);
            }
            return response;
        }));

运行后,"response.headers.get('auth-token')“的值为空。有没有办法解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-17 18:32:19

如果使用CORS,则需要指定Access-Control-Expose-Headers (请参阅documentation)服务器端。

代码语言:javascript
复制
Access-Control-Expose-Headers: auth-token, OtherCustomHeader
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66239875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档