当我发出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' )
);
答案 0 :(得分:0)
您可以将withCredentials: true
设置为appropriate XHR option,以使Cookie和标头得到不同的对待。
然后,在请求完成后,使用document.cookie或some other library
访问cookie类似:
ajax("https://some-url").subscribe(
res => {
console.log(document.cookie);
}
);