Angular 4-无法从响应头中获取Set-Cookie

时间:2018-07-04 11:49:26

标签: angular cookies http-headers response

我正在尝试从响应头中获取“ Set-Cookie”值。我能够成功获取带有除“ Set-Cookie”以外的所有键值对的Response Header。已经针对同一问题尝试了该论坛中提供的多种解决方案。以下是相同的链接:

Angular 2 - Get cookie from response

Angular 4 Unable to Get Cookies From Header Response

angular2/http get location header of 201 response

Restrictions of XMLHttpRequest's getResponseHeader()?

最后一个链接是这样的:“ XMLHttpRequest API的当前状态仅限制对Set-Cookie和Set-Cookie2标头字段的访问

我正在使用Http模块在Angular 4上工作,并且Http模块使用XMLHttpRequest作为默认后端执行http请求。因此,如果是这种情况,我将如何从响应标头访问“ Set-Cookie”值。我真的不希望现在迁移到HttpClient模块,因为我现在已经在多个组件中注入了Http模块。对于我的应用程序来说,这将是一个很大的变化。因此,如果有人可以提供有关HttpModule的解决方案,这将非常有帮助。下面是我的代码:

public getReportData2(apiURL)

{      
  var headers = new Headers();
  headers.append('Content-Type', 'application/json');
  let options = new RequestOptions({ headers: headers,withCredentials:true});

  return this.http.get(apiURL,options)
  .subscribe((res:Response) => console.log(res));

}

以下是我得到的回复:

enter image description here

下面是我可以在控制台中看到的标题:

enter image description here

谢谢。

0 个答案:

没有答案
相关问题