HarmonyOS 鸿蒙Next真机不能进行网络请求,模拟器完美实现。No Network Security Config specified, using platform default
HarmonyOS 鸿蒙Next真机不能进行网络请求,模拟器完美实现。No Network Security Config specified, using platform default
config.json代码如下(已设置网络权限,而且是https请求链接):
“deviceConfig”: { “default”: { “network”: { “cleartextTraffic”: true } } }, “module”: { “reqPermissions”: [ { “name”: “ohos.permission.INTERNET” } ],
}
为什么在模拟器上能运行,在真机上无法进行网络请求,并报错No Network Security Config specified, using platform default。(使用的是JS开发,不是Java)
网络请求代码如下所示:
//界面初始化网络JSON数据获取
fetch: function () {
var that = this;
fetch.fetch({
url: “https://harmony-1300376177.cos.ap-shanghai.myqcloud.com/swiper_item.json”,
success: function (response) {
console.info(“网络请求成功”);
that.responseData = JSON.parse(response.data);
},
fail: function () {
console.info(“网络请求错误”);
}
});
},
以下代码本地测试OK,请参考,也可以贴出详细报错日志进一步分析。
btn(){
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>let that = this;
fetch.fetch({
url: “https://harmony-1300376177.cos.ap-shanghai.myqcloud.com/swiper_item.json”,
success:function (response) {
console.info(“网络请求成功”);
that.responseData = JSON.stringify(response.data);
console.log(that.responseData+“数据”);
},
fail:function () {
console.info(“网络请求错误”);
},
complete(){
}
});
},
我刚刚遇到的, 真机调试 没有网络;
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/RmeSchedManager: SetMarginData, input:3, animation:4, traversal:4, util:600, frameRate:60
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
LOG
07-06 17:49:23.270 22762-24539/com.example.tutuxiaowu D NetworkSecurityConfig: No Network Security Config specified, using platform default
07-06 17:49:23.452 22762-24540/com.example.tutuxiaowu D NetworkSecurityConfig: No Network Security Config specified, using platform default
07-06 17:49:23.612 22762-24541/com.example.tutuxiaowu D NetworkSecurityConfig: No Network Security Config specified, using platform default
HarmonyOS 鸿蒙系统Next真机无法进行网络请求,而模拟器表现正常,提示“No Network Security Config specified, using platform default”通常指示安全配置未明确指定。请检查真机应用的安全配置文件(如network_security_config.xml),确保正确配置了必要的网络安全设置,如信任的网络证书或自签名证书的处理。同时,检查应用权限设置,确保已授权网络访问权限。如果问题依旧没法解决请加我微信,我的微信是itying888。