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

相关推荐
Rainman博9 小时前
WMS-窗口relayout&FinishDrawing
android
baidu_2474386111 小时前
Android ViewModel定时任务
android·开发语言·javascript
有位神秘人12 小时前
Android中Notification的使用详解
android·java·javascript
·云扬·12 小时前
MySQL Binlog落盘机制深度解析:性能与安全性的平衡艺术
android·mysql·adb
独自破碎E13 小时前
【BISHI9】田忌赛马
android·java·开发语言
代码s贝多芬的音符14 小时前
android 两个人脸对比 mlkit
android
darkb1rd16 小时前
五、PHP类型转换与类型安全
android·安全·php
gjxDaniel16 小时前
Kotlin编程语言入门与常见问题
android·开发语言·kotlin
csj5016 小时前
安卓基础之《(22)—高级控件(4)碎片Fragment》
android
峥嵘life17 小时前
Android16 【CTS】CtsMediaCodecTestCases等一些列Media测试存在Failed项
android·linux·学习