React native 使用多集cookie响应本机fetch/XMLHttpRequest post请求
我想从web服务器接收多个设置Cookie值。 目前,我只收到标题中的最后一组Cookie。React native 使用多集cookie响应本机fetch/XMLHttpRequest post请求,react-native,xmlhttprequest,fetch-api,React Native,Xmlhttprequest,Fetch Api,我想从web服务器接收多个设置Cookie值。 目前,我只收到标题中的最后一组Cookie。 XMLHttpRequest: var formData = new FormData(); formData.append('userId', state.userId); formData.append('password', state.password); var http = new XMLHttpRequest(); var url = "http://myurl"; http
XMLHttpRequest:
var formData = new FormData();
formData.append('userId', state.userId);
formData.append('password', state.password);
var http = new XMLHttpRequest();
var url = "http://myurl";
http.open("POST", url);
http.setRequestHeader("Content-type", "multipart/form-data");
http.withCredentials = true;
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
console.log(http.responseText);
console.log(http.getAllResponseHeaders());
}
}
http.send(formData);
获取:
fetch('http://myurl', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
},
credentials: 'same-origin',
body: formData
})
.then((response) => {
console.log(response);
console.log(response.headers.getAll('set-cookie'));
return response.json()
})
.then((responseJson) => {
console.log('responseJson', responseJson);
console.log('formData', formData);
setLoginBool(responseJson.success);
})
.catch((error) => {
console.error(error);
});
我已经添加了邮递员请求的结果和获取结果的日志。
似乎只接收到最后一组Cookie值。
您找到解决方案了吗?我这里也有同样的问题。我解决这个问题的方法是在react本机代码中使用“credentials:“same origin”。