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 的资料越来越少了,自己看源码可能还快一些~

相关推荐
晚风叙码15 小时前
MySQL 表的约束详解:从空属性到外键
android·数据库·mysql·adb
alexhilton1 天前
模块化Jetpack Compose架构
android·kotlin·android jetpack
厮年断弦1 天前
AI 辅助开发实录:一周做完一个 Android 本地音乐播放器,这些坑替你踩了
android
hai_android1 天前
InputStage 责任链核心执行流程
android·android studio·android jetpack
mmsx1 天前
Android 测绘计算工程化:七四参数、高程拟合与单位系统
android·kotlin
我是场1 天前
我的NPI项目之-Touch的EE特性
android·arm开发
天空之城--1 天前
Android一周动态:AI编程、Compose与车载生态新信号
android·flutter
恋猫de小郭1 天前
Dart 4.0 要彻底移除 dart:mirrors,Augmentations 应该要来了
android·前端·flutter
Carson带你学Android1 天前
Gemini 4 Argon 发布:对 Android 开发者意味着什么?
android·ai编程
事圆则缓2 天前
Kotlin Flow、StateFlow、SharedFlow 全解析:冷流、热流与 Android 状态管理
android·kotlin·php