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

相关推荐
CHB7 小时前
uni-app x 蒸汽模式 性能测试基准报告 Benchmark【Android版】
android·ios·uni-app
带娃的IT创业者8 小时前
拆掉那堵墙:LibrePods 如何让 AirPods 在 Android 上重获新生
android·开源项目·airpods·librepods·生态解锁
_阿南_9 小时前
flutter 展示的字体突然奔放了
android·flutter·ios
文人sec12 小时前
MySQL事务与索引做了什么?
android·笔记·mysql
刘洋浪子13 小时前
AndroidStudio保存日志菜单
android
朱涛的自习室13 小时前
从 Prompt 到 Graph:AI 工程的进化史
android·前端·人工智能
2501_9327502614 小时前
Android 中 Serializable 与 Parcelable 的对比与选择
android
1570925113415 小时前
ViewBinding与DataBinding区别与选型
android
Android-Flutter16 小时前
不阻塞线程
android·kotlin
小乖写代码17 小时前
49款开源Android小游戏
android·游戏