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

相关推荐
时光呀时光慢慢走12 小时前
MAUI 开发安卓 MQTT 客户端:实现远程控制 (完整源码 + 避坑指南)
android·物联网·mqtt·c#
成都大菠萝12 小时前
2-2-44 快速掌握Kotlin-函数类型操作
android
有位神秘人13 小时前
Android中获取设备里面的音频文件
android
2501_9159184113 小时前
使用 HBuilder 上架 iOS 应用时常见的问题与应对方式
android·ios·小程序·https·uni-app·iphone·webview
farewell-Calm14 小时前
01_Android快速入门
android
helloCat14 小时前
记录CI/CD自动化上传AppGallery遇到的坑
android·前端·api
WordPress学习笔记15 小时前
wordpress根据页面别名获取该页面的链接
android·wordpress
2501_9160074715 小时前
iOS 崩溃日志的分析方法,将崩溃日志与运行过程结合分析
android·ios·小程序·https·uni-app·iphone·webview
浅箬15 小时前
Taro3的H5项目在Android、IOS 中因为兼容性问题导致的白屏问题
android·团队开发·taro
技术摆渡人15 小时前
Android 全栈架构终极指南:从 Linux 内核、Binder 驱动到 Framework 源码实战
android·linux·架构