开发者社区> 问答> 正文

QN.fetch在h5端设置自定义http协议头无效

黑色小刀 2017-07-04 15:45:15 1102

if (!this.className) {

        alert("[F.Ajax]未设置className");
        return false
    }
    if (!this.methodName) {
        alert("[F.Ajax]未设置methodName");
        return false
    }

    let requestPath = null;
    try {
        requestPath = Util.Location.pathname
    } catch (e) {
        requestPath = "null"
    }
    let requestUrl = (Ajax.contextPath == null ? "" : Ajax.contextPath) + "/service/ajax?path=" + requestPath + "&time=" + (new Date()).getTime();
    let requestVar = "";
    for (let i = 0; i < this.params.length; i++) {
        let param = "" + this.params[i];
        if (param.indexOf("#") != -1) {
            param = param.replace(/\#/g, "-%2-%-3%-")
        }
        requestVar = requestVar + "%23" + encodeURIComponent(param) + "%23"
    }
    let requestHeader = new Object();
    requestHeader["X-Requested-With"] = "XMLHttpRequest";
    requestHeader["X-RMI-Class"] = this.className;
    requestHeader["X-RMI-Method"] = this.methodName;
    if (this.token) {
        requestHeader["X-RMI-Token"] = this.token
    }
    requestHeader["Content-Type"] = "text/plain; charset=UTF-8";
    requestHeader["Content-Length"] = requestVar.length;
    requestHeader["Connection"] = "close";
    return QN.fetch(requestUrl, {
        method: "POST",
        headers: requestHeader,
        body: requestVar,
        dataType: "text",
        mode: "no-cors"
    }).then((response)=>{
        return this.receive(response);
    });

这是我的代码,如图设置了譬如X-**之类的协议头,在移动端完全正常,在h5端抓包如下图
image

分享到
取消 提交回答
全部回答(1)
  • 1979304775307615
    2019-07-17 21:21:47

    mode为no-cors时,是不能够设置headers的

    0 0

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程