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

相关推荐
冬奇Lab4 小时前
PowerManagerService(下):Doze模式与电池优化
android·源码阅读
砖厂小工5 小时前
Compose 中函数引用 vs Lambda:到底该用哪个?
android
Kapaseker15 小时前
详解 Compose background 的重组陷阱
android·kotlin
黄林晴16 小时前
Kotlin 2.3.20-RC2 来了!JPA 开发者狂喜,6 大更新一文速览
android·kotlin
kymjs张涛1 天前
OpenClaw 学习小组:初识
android·linux·人工智能
范特西林1 天前
实战演练——从零实现一个高性能 Binder 服务
android
范特西林1 天前
代码的生成:AIDL 编译器与 Parcel 的序列化艺术
android
范特西林1 天前
深入内核:Binder 驱动的内存管理与事务调度
android
范特西林1 天前
解剖麻雀:Binder 通信的整体架构全景图
android
范特西林1 天前
破冰之旅:为什么 Android 选择了 Binder?
android