Cordova "Origin: file://"-错误使用和Android 10,旧版本工作
Cordova "Origin: file://"-Error using and Android 10, older versions working
我做了一个 Cordova 应用程序,它使用 ajax xml 将地理数据 (WFS) 发送到服务器 (geoserver)。服务器启用了 CORS 并设置了 CORS Origin-Filters(浏览器版本需要,此过滤器目前设置为 *,因此允许任何来源)。
POST-任务工作 (!!) Android 9,使用 Android 10 我收到“错误 403”,因为 Android 10 发送 Origin:file :// 在 POST 中表示 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-头包含
<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" />
经过几天的工作,我可以通过将 apache tomcat 服务器更新到新版本来解决这个问题!这解决了使用 CORS 过滤器 *
的问题
我做了一个 Cordova 应用程序,它使用 ajax xml 将地理数据 (WFS) 发送到服务器 (geoserver)。服务器启用了 CORS 并设置了 CORS Origin-Filters(浏览器版本需要,此过滤器目前设置为 *,因此允许任何来源)。 POST-任务工作 (!!) Android 9,使用 Android 10 我收到“错误 403”,因为 Android 10 发送 Origin:file :// 在 POST 中表示 Origin“null”,这会导致此错误。
我花了几个小时阅读帖子并试图解决这个问题,但我做不到。
任何人都可以帮助我 - 非常好!
这是我的 Ajax-Post
的 jstransactWFS = 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-头包含
<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" />
经过几天的工作,我可以通过将 apache tomcat 服务器更新到新版本来解决这个问题!这解决了使用 CORS 过滤器 *
的问题