RxJS Ajax如何获取响应cookie

时间:2019-02-23 22:49:06

标签: javascript ajax cookies rxjs

当我发出RxJS Ajax调用请求时,我设置了请求的标题,但是如何获取RxJS Ajax Response的Cookie?

import { ajax } from 'rxjs/ajax';
ajax({
    url: "some url",
    body: {
        parameter1: "abc",
        parameter2: "def"
    },
    headers: {
        "Content-Type": "application/json",
        "Cache-Control": "no-cache"
    },
    method: 'POST',
    responseType: 'json'
})
.subscribe(
    payLoad => {
        console.log(payLoad);
        console.log(payLoad.headers);
    },
    error => console.log(error),
    () => console.log( 'done' )
);

1 个答案:

答案 0 :(得分:0)

您可以将withCredentials: true设置为appropriate XHR option,以使Cookie和标头得到不同的对待。

然后,在请求完成后,使用document.cookiesome other library

访问cookie

类似:

ajax("https://some-url").subscribe(
  res => {
    console.log(document.cookie);
  }
);