[LayaAir3]HttpRequest自定义了headers,就会报跨域的问题,是设置的方式不对吗?
let xhr = new Laya.HttpRequest();如果去掉headers,就是一个正常的请求,只是404,因为没有自定义headers
xhr.http.withCredentials = true; // 确保请求带上 cookie
// xhr.once(Laya.Event.COMPLETE, this, onRequestComplete);
// xhr.once(Laya.Event.ERROR, this, onRequestError);
let headers = [
"user_id", "1"
];
xhr.send(url, null, "get", "json", headers);
let xhr = new Laya.HttpRequest();如果这样设置,就会报Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.
xhr.http.withCredentials = true; // 确保请求带上 cookie
// xhr.once(Laya.Event.COMPLETE, this, onRequestComplete);
// xhr.once(Laya.Event.ERROR, this, onRequestError);
xhr.http.setRequestHeader("client", "3");
xhr.send(url, null, "get", "json");
该怎么自定义一些请求头参数呢???
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
谷主
赞同来自: