我在cocos creator上写的http传输脚本,无论是在浏览器上还是模拟器上都没有任何问题, 但一打包到安卓上就连不上网,服务端没有任何消息说明请求根本没发过去,底下是我写的脚本,求助各位大佬能否帮我看一下哪里出了问题
module.exports={
sendPostForms:function(urlApi,paramJson,callback){
//URL未设置
var xhr=new XMLHttpRequest();
this.responseCallback(xhr,callback);
xhr.timeout=5000;
xhr.open("POST","http://106.52.82.57:8000"+"/"+urlApi);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
var args='';
for(var i=0;i<paramJson.length;i++){
cc.log(paramJson[i]);
args+=paramJson[i].key+"="+paramJson[i].value+"&";
}
xhr.send(args);
},
responseCallback:function(xhr,callback){
var alert=true;
xhr.onreadystatechange=function(){
console.log(xhr.statusText);
if(xhr.readyState==4&&(xhr.status>=200&&xhr.status<=207)){
alert=false;
var httpStatus=xhr.statusText;
var response=xhr.responseText;
callback(response);
}
}
setTimeout(function(){
if(alert){
callback(JSON.stringify({success:false,res:"错误:网络异常"}));
}
},5000);
},
}