[]打包app,http无法设置content-type

我明明设置了content-type为json,在浏览器里都正常,但是在手机运行器里就无法使用,我发的数据为"{"a":1}",到服务器上变成了 "{"a":1}"="",content-type也变成了application/x-www-form-urlencoded
 
代码如下:
static httpRequest(method:string, url:string, data:any, headers:Array<string>, cb:(err:Error, data?:any)=>void) {
let req = new Request();

req.on(Event.COMPLETE, this, (data) => {
cb(null, data);
});

req.on(Event.ERROR, this, (err) => {
console.error(err);
cb(err);
});

let body = data;
let tp = typeof data
if(tp === 'object' || tp === 'array'){
if(method === 'post' || method === 'put') {
body = JSON.stringify(data);
} else {
let query = "";
let first = true;
for(let k in data) {
if(!first){
query += '&';
} else {
first = false;
}
query += k + "=" + data[k];
}
if(url.indexOf('?') != -1) {
url += "&" + query;
} else {
url += "?" + query;
}
body = null;
}
}

headers = headers || [];
let hasContentType = false;
for(let k of headers) {
if(k.toLowerCase() === "content-type"){
hasContentType = true;
break;
}
}

if(!hasContentType){
headers.push("content-type", "application/json");
}

req.send(url, body, method, "json", headers);
}
Net.httpRequest("post","http://xxxx",{a:1},null,cb)
已邀请:

Laya_XS

赞同来自:

这个问题我们记录下,节后测试下,谢谢反馈问题!

要回复问题请先

商务合作
商务合作