首页 > 解决方案 > 无法从 HTTP 响应访问授权标头

问题描述

我有以下代码

authenticate(username: string, password: string) {
    this.callAuthenticationEndpoint(username, password).subscribe(resp => {
      console.log(resp.headers)
      console.log(resp.headers.get('Authorization'))
    })
  }

  callAuthenticationEndpoint(username: string, password: string): Observable<any> {
    var url = this.AUTHENTICATE_URL + 'username=' + username + '&password=' + password;
    var headers = new HttpHeaders().set('Content-Type', 'application/json')
    return this.http.get(url, {headers: headers, observe: "response"});
  }

这调用了我使用 Spring 编写的后端。在与 Angular 集成之前,我已经对其进行了测试,所以我确信它可以工作。另外,当我调用上面的方法时,我在 Chrome 中得到了这个

在此处输入图像描述

但由于某种原因,我无法在代码中访问这些数据..

在此处输入图像描述

标签: angularrestspring-securityjwtangular-httpclient

解决方案


推荐阅读