javascript - Cordova "Origin: file://"-Error using and Android 10, old versions working
问题描述
我做了一个 Cordova 应用程序,使用 ajax xml 将地理数据 (WFS) 发送到服务器 (geoserver)。服务器启用了 CORS 并设置了 CORS 源过滤器(浏览器版本需要此过滤器,此过滤器目前设置为 *,因此允许任何源)。POST 任务 (!!) 最多适用于 Android 9,使用 Android 10 我收到“错误 403”,因为 Android 10 在 POST 中发送 Origin:file://,这意味着 Origin“null”会导致此错误。
我已经阅读了几个小时的帖子并试图解决这个问题,但我无法做到。
任何人都可以帮助我 - 会非常好!
这是我的 Ajax-Post 的 js
transactWFS = function (mode, f) {
var node;
switch (mode) {
case 'insert':
node = formatWFS.writeTransaction([f], null, null, formatGML);
break;
case 'update':
node = formatWFS.writeTransaction(null, [f], null, formatGML);
break;
case 'delete':
node = formatWFS.writeTransaction(null, null, [f], formatGML);
break;
}
var payload = xs.serializeToString(node);
$.ajax('https://server.com/geoserver/database/ows', {
type: 'POST',
dataType: 'xml',
processData: false,
contentType: 'text/xml',
data: payload,
}).done(function () {
//sourceWFS.clear();
});
};
html-head 包含
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data:">
config.xml 包含
<plugin name="cordova-plugin-whitelist" source="npm" spec="~1.3.4" />
<access origin="*" />
<allow-navigation href="*"/>
解决方案
安装这个插件https://github.com/globules-io/cordova-plugin-ios-xhr
然后将您的偏好设置为
<preference name="allowFileAccessFromFileURLs" value="true" />
<preference name="allowUniversalAccessFromFileURLs" value="true" />
<preference name="InterceptRemoteRequests" value="all" />
推荐阅读
- javascript - MomentJS 在进行格式化时更改时间
- python-3.x - libjson2csv 包使用指南
- xslt - XSLT:将后续标签选择到子段中,直到下一个标签
- python - 如何在 xlsx 文件中将 DataFrame 保存到 Sheet2
- python - 将 Tableau 连接到运行 TabPy 的 GCP 计算实例
- android - 在哪里添加用于在android中检查应用程序更新的代码,如果我在启动画面中这样做会好吗?还是主要活动?
- vue.js - 为什么当我尝试动态更改图像路径时,我只能看到 alt 信息?
- azure - 查找使用 Azure 网络接口附加的资源
- reactjs - React 中的 gRPC 流式处理未按预期工作
- python - 如何在 Python 中读取类中的数据文件?