我想从Web服务器接收多个Set-Cookie值。 目前我只在我的标题中收到最后一个Set-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.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);
});
我添加了邮递员请求的结果和获取结果的日志。 似乎只收到了最后一个Set-Cookie值。 postman result fetch log result