Cordova 12 Android 不支持 http 原因探索

最近在升级 Cordova 到最新版本,升级完成后发现无法请求网络,研究了两次最终发现解决方案。

发现控制台中有日志输出,提示当前是 https ,无法直接访问 http。

复制代码
[INFO:CONSOLE(225)] "Mixed Content: The page at 'https://localhost/index.html' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http:// ....'. This request has been blocked; the content must be served over HTTPS.", source: webpack:///./node_modules/@sentry/browser/esm/integrations/trycatch.js? (225)

开始去查找 config.xml 文件,此时花费了比较多的实际无果。然后就去查代码,在 Android 中查到源码。

从代码可以看出从配置项中获取配置,如果没有就默认为 https。这样解决方案就简单了,直接给一个配置项就可以了。

复制代码
<platform name="android">
        <preference name="Scheme" value="http"/>
</platform>

不得不感慨,Cordova 的资料越来越少了,自己看源码可能还快一些~

相关推荐
海兰18 小时前
【SpringBoot 】AOP企业级权限控制方案(二)
android·java·spring boot
阿pin18 小时前
Android随笔-启动Zygote的rc文件是什么?
android·zygote·rc
帅次1 天前
Android 高级工程师面试:Java 基础知识 近1年高频追问 22 题
android·java·面试
私人珍藏库1 天前
[Android] zip解压缩管理-全格式压缩包一键解压+打包
android·app·生活·工具·多功能
雨白1 天前
C语言:动态内存分配
android
Android-Flutter1 天前
android compose 自定义Painter绘制图形 使用
android·kotlin·compose
我是一颗柠檬1 天前
【Java项目技术亮点】覆盖索引与索引下推优化
android·java·开发语言
vigor5121 天前
MySQL通过Mango实现分库分表
android·数据库·mysql
阿pin1 天前
Android随笔-Zygote中fork究竟是什么?
android·zygote·fork