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

相关推荐
__Witheart__13 小时前
Android 驱动编译为模块或者built-in内核
android·linux·数据库
恋猫de小郭13 小时前
Flutter 最好的 AI 自动化测试工具:Patrol
android·前端·flutter
流星白龙13 小时前
【MySQL高阶】16.行结构
android·mysql·adb
HQL_seven13 小时前
Android 四大组件解析
android
Digitally13 小时前
适用于安卓、iOS 和电脑的最新文件共享应用评测指南
android·ios·电脑
__Witheart__14 小时前
搭建编译 HW-T3568 安卓固件的环境
android
Bowen_J14 小时前
Flutter 屏幕旋转适配
android·flutter·ios
程序员陆业聪1 天前
绕过Frida/Xposed的最后防线:SVC直接系统调用与Native反Hook实战
android
程序员陆业聪1 天前
WebView与原生JS交互:JSBridge生产级实现与安全防护
android
我命由我123451 天前
Android 开发问题:MlKitException: An internal error occurred during initialization.
android·java·java-ee·android jetpack·android-studio·androidx·android runtime