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

相关推荐
wxson72821 天前
【Android视频监控系统技术总结】
android·音视频
hunterandroid1 天前
[Android 从零到一] LiveData 粘性事件与单次消费:从重复触发到可靠事件总线
android
hunterandroid1 天前
[Android 从零到一] Android 事件分发机制:从 ACTION_DOWN 到 View 事件消费链路
android
阿巴斯甜1 天前
adb‑shell 全套命令实操总结
android
奔跑的架构师1 天前
[A-49]ARMv9/v8-PSCI接口规范与工作流程简介
android·linux·arm开发·arm
AFinalStone1 天前
Android 7系统国际化(七)Resources 与 AssetManager 源码剖析
android·国际化·local
Android-Flutter1 天前
Android 内存泄漏详解
android·kotlin
catchadmin1 天前
Fiber 与 PHP 8.6 Polling API 异步初探
android·开发语言·php
Android-Flutter1 天前
android Handler , Looper , Message , MessageQueue 详解
android·kotlin