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

相关推荐
时间的拾荒人7 小时前
MySQL C语言连接 - 从入门到实战
android·c语言·mysql
Meteors.7 小时前
Android性能优化:01. 指标体系 + 分析工具链
android
jike_20269 小时前
安卓平台免费录音转文字工具深度测评:5 款 APP 功能对比与选型指南
android·智能电视
Code Man9 小时前
Windows 下使用 Appium
android·windows·appium
码农coding9 小时前
android 12 中的VSYNC接收
android
GitLqr9 小时前
Flutter 3.44 性能飞跃:深度解析 Android Platform View 的 HCPP 新特性
android·flutter·性能优化
码农coding9 小时前
android 12 SurfaceFlinger中的CompositionEngine
android
Mem0rin11 小时前
[MySQL] 聚合函数、分组查询、连接查询
android·mysql
码龙-DragonCoding11 小时前
一键批量提取音频、提取视频
android·音视频·提取
祉猷并茂,雯华若锦11 小时前
Win下完美解决Allure报错,生成Web自动化测试报告
android·python·selenium·自动化