qq_30270249 2019-07-07 09:37 采纳率: 0%
浏览 443
已结题

求助:程序打包到Android后连不上网

我在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);
    },
}
  • 写回答

2条回答 默认 最新

  • threenewbee 2019-07-07 09:47
    关注

    抓包看下,你的手机本身能不能访问106.52.82.57:8000
    还有就是你的app有没有联网的权限。
    如果服务器也是你写的,在你的服务器上搞一个网页,通过你手机浏览器访问看看。多半还是网络、权限的问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?