杨婆婆管家家
杨婆婆管家家
  • 发布:2021-06-04 15:37
  • 更新:2021-06-10 15:39
  • 阅读:458

【报Bug】mui.ajax&&uni.request&&XMLHttpRequest跨域请求4g网络超时,wifi正常

分类:HTML5+

产品分类: HTML5+

HBuilderX版本号: 3.1.17

手机系统: 全部

打包方式: 云端

测试过的手机:

安卓4-6 苹果7苹果sxmax

示例代码:

mui.ajax('http://admin.wsjnjs.cqgh.org/api/nominees/setlike',{
data:{
id: "6287", openid: undefined
},
crossDomain: true,
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout: 10000,//超时时间设置为10秒;
headers:{'Content-Type':'application/json'},
success:function(data){
console.log(JSON.stringify(data))
//服务器返回响应,根据响应结果,分析是否登录成功;
},
error:function(xhr,type,errorThrown){
//异常处理;
console.log(type);
}
});

操作步骤:

运行这个函数请求即可

预期结果:

预期能和正常返回结果数

实际结果:

报超时错误

bug描述:

uni-app html5+

mui.ajax
uni.request
XMLHttpRequest
3种网络请求跨域模式
在4g网络下都超时
在wifi模式下正常

2021-06-04 15:37 负责人:无 分享
已邀请:
DCloud_iOS_XHY

DCloud_iOS_XHY

换成 5+的 plus.net 接口发送请求吧,mui早已停止维护了

  • 杨婆婆管家家 (作者)

    plus.net.XMLHttpRequest和uni.request的跨域在4g环境下都用不了

    我都已经测试过

    var xhr = new plus.net.XMLHttpRequest(); // 创建跨域请求

    // 请求返回

    xhr.onload = function () {

    if (xhr.responseText.code == 1001) {

    voteQuantity = 30;

    } else {

    voteQuantity++;

    }

    }

    // 超时超时

    xhr.ontimeout = function (e) {

    console.log(JSON.stringify(e), "-------")

    }

    xhr.open( "POST", "http://admin.wsjnjs.cqgh.org/api/nominees/setlike" );

    xhr.send(JSON.stringify({id: "6287", openid: undefined}));

    2021-06-09 14:58

杨婆婆管家家

杨婆婆管家家 (作者) - 80后

plus.net.XMLHttpRequest和uni.request的跨域在4g环境下都用不了  

我都已经测试过  

var xhr = new plus.net.XMLHttpRequest(); // 创建跨域请求  

// 请求返回  

xhr.onload = function () {  

if (xhr.responseText.code == 1001) {  

voteQuantity = 30;  

} else {  

voteQuantity++;  

}  

}  

// 超时超时  

xhr.ontimeout = function (e) {  

console.log(JSON.stringify(e), "-------")  

}  

xhr.open( "POST", "http://admin.wsjnjs.cqgh.org/api/nominees/setlike" );  

xhr.send(JSON.stringify({id: "6287", openid: undefined}));
DCloud_iOS_XHY

DCloud_iOS_XHY

  • 杨婆婆管家家 (作者)

    我是在手机上打包成app运行的

    而且wifi环境跨域没问题

    4g网络环境就不行

    如果是配置问题那应该2种网络情况都是一样的吧

    2021-06-15 14:38

该问题目前已经被锁定, 无法添加新回复