CocosCreator 1.9.3 使用XMLHttpRequest,发送post请求,服务器端返回两个set-cookie值,但是客户端只能解析出一个set-cookie值。是不是没有考虑两个情况?求解答。理论上说如果服务器返回两个,那么客户端收到的set-cookie应该是一个数组,里面包含了两个值,目前还是字符串。该怎么处理?
下面附上代码:
var http_post = function (url, data, callback) {
var xhr = cc.loader.getXMLHttpRequest();
xhr.timeout = 5000;
if (data == null) data = {};
xhr.open(“POST”, url, true);
if (cc.sys.isNative) {
xhr.setRequestHeader(“Accept-Encoding”, “gzip,deflate”, “application/x-www-form-urlencoded;charset=UTF-8”);
var timer = setTimeout(function() {
xhr.hasRetried = true;
xhr.abort();
console.log('http timeout');
retryFunc();
}, 5000);
var retryFunc = function() {
exports.http_post(url, data, callback);
xhr.onreadystatechange = function () {
clearTimeout(timer);
if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
cc.log("Object.keys(xhr)");//
//var obj = xhr.getAllResponseHeaders();
var obj = xhr.getResponseHeader("set-cookie");
cc.log(obj)
var respText = xhr.responseText;
var ret = null;
try {
ret = JSON.parse(respText);
} catch (e) {
console.log("err:" + e);
if (callback) {
callback(ret);
callback = null;
else if (xhr.readyState === 4) {
if(xhr.hasRetried){
return;
console.log('other readystate == 4' + ', status:' + xhr.status);
setTimeout(function() {
retryFunc();
}, 5000);
else {
console.log('other readystate:' + xhr.readyState + ', status:' + xhr.status);
try {
//cc.log(JSON.stringify(data));
xhr.send(data);
//xhr.send(data);
catch (e) {
//setTimeout(retryFunc, 200);
retryFunc();
return xhr;