获取-返回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将是我的后备。