【问题标题】:RxJS Ajax how to get response cookieRxJS Ajax如何获取响应cookie
【发布时间】:2019-02-24 08:12:23
【问题描述】:

当我发出 RxJS Ajax 调用请求时,我设置了请求的标头,但是如何获取 RxJS Ajax 响应的 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' )
);

【问题讨论】:

    标签: javascript ajax cookies rxjs


    【解决方案1】:

    您可以将withCredentials: true 设置为appropriate XHR option,以便对cookies 和标头进行不同的处理。

    然后,请求完成后,使用document.cookiesome other library访问cookie

    类似:

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

    【讨论】:

      猜你喜欢
      • 2012-10-02
      • 2019-09-16
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多