使用angular 2 HTTP get发送cookie跨域

时间:2018-03-09 15:25:27

标签: angular

如何使用Angular 2跨域发送cookie:

  const headers = new Headers({ 'Cookie': 'test=me'});

  let options = new RequestOptions({ headers });

  return this.http.get(this.specialUrl, options )
    .map( (res: Response ) => res.json());

我在标题中看不到它:

Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Cache-Control: no-cache
Connection: keep-alive
Host: api.crm.test
Origin: http://front-end:4200
Pragma: no-cache
Referer: http://front-end:4200/
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101     Firefox/60.0

任何帮助表示感谢。

由于

更新。审判;

  const headers = new Headers({ 'Cookie': 'test=me'});

  let options = new RequestOptions({ headers, withCredentials: true});

return this.http.get(this.specialUrl, options )
  .map( (res: Response ) => res.json());

一切都在编译。

1 个答案:

答案 0 :(得分:0)

您缺少headers参数名称。试试这个:

const headers = new Headers({ 'Cookie': 'test=me'});
return this.http.get(this.specialUrl, { headers: headers} )
    .map((res: Response ) => res.json());