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

相关推荐
Android-Flutter12 小时前
flutter async/await 详解
android·flutter
步行cgn12 小时前
Spring Boot 中的 YAML 完全指南
android·spring boot·firefox
事圆则缓13 小时前
Java 常见数据结构与 Android 使用场景
android·java·数据结构
RisunJan13 小时前
Android 高频面试题与解答
android
MyBili13 小时前
【安卓开发/搞机】快图浏览(QuickPic)技术解析:为何这款3MB应用仍是本地图库的性能天花板?
android·app·安卓·文件管理·相册·看图软件·手机相册
事圆则缓14 小时前
Kotlin 高阶工程化与 Android 深入实践
android·开发语言·kotlin
zhangphil14 小时前
AI大模型生成maxTokens 与上下文context
android·llama
淡淡的香烟14 小时前
Androidiot开发之猫脸识别
android·物联网
2501_9151063214 小时前
iOS数据采集技术详解:从性能监控到崩溃分析的全链路实践
android·ios·小程序·https·uni-app·iphone·webview
天空之城--1 天前
Android Koin 完全指南:从原理到实践
android