提取返回cookie Axios的设置不相同

时间:2018-08-08 15:22:08

标签: cookies fetch axios

获取-返回cookie

 fetch(url, {
        method: "POST",
        //cache: 'no-cache', //Working do not mess with
        //mode: 'no-cors', //Working do not mess with
        headers: {
          'Accept':  'application/json',
          'Content-Type': 'application/json',
        },
        credentials: 'same-origin', //Works because Lando uses localhost.
        body: JSON.stringify(data),
        })
        .then(function(response) {
          return response.json();
        })
        .then(function(myJson) {
          console.log(myJson);
          that.setState({csrfToken: myJson.csrf_token}); //Eventually we want to set the returned values to apollo link state!
        })
        .catch(function (error) {
          console.log(error);
      });
      };

Axios-不返回cookie

axios({
    method: 'post',
    url,
    data,
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    //cache: 'no-cache', //Working do not mess with
    mode: 'no-cors', //Working do not mess with
    withCredentials: true,
    credentials: 'same-origin', //Works because Lando uses localhost.
  })
    .then(function (response) {
      console.log(response);
    })
    .catch(function (error) {
      console.log(error);
    });
  };

有什么想法吗?

理想情况下,出于支持浏览器的原因,我想使用Axios。如果我不知道如何实现此功能,Polyfilling Fetch将是我的后备。

0 个答案:

没有答案