我已引用https://github.com/apache/cordova-plugin-whitelist并将其添加到我的config.xml中:
<plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
<access origin="*" subdomains="true"/>
<!-- A wildcard can be used to whitelist the entire network,
over HTTP and HTTPS.
*NOT RECOMMENDED* -->
<allow-navigation href="*"/>
<allow-intent href="*"/>
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
我的AndroidManifest.xml中也具有以下权限:
<uses-permission android:name="android.permission.INTERNET" />
以下是index.html中的CSP声明:
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *;script-src 'self' localhost:35729 84.254.133.91:8080 'unsafe-inline' 'unsafe-eval';connect-src *">
服务器正在运行@ 84.254.133.91:8080
这是带有http post调用的代码:
var req = {
method: 'POST',
url: $rootScope.labels.IP + $rootScope.labels.USER_ID_CREATE_URL,
data: {
userId: $scope.newUserIdCreate.username,
password: $scope.newUserIdCreate.password,
}
};
var res = $http(req);
res.success(function (data, status, headers, config) {
alert("request success:" + JSON.stringify({ data: data }));
});
res.error(function (data, status, headers, config) {
alert("request failed:" + JSON.stringify({ data: data }));
});
$ http请求均未通过。我已经花了将近2天的时间,转介了n篇文章,但仍然无法破解这个问题。
此外,我添加了一个指向“ google / facebook”的href链接,并且能够从该应用访问这些网站。
通过运行“离子服务”使用网络应用程序可以很好地工作。从Android APK上,没有任何请求到达服务器。
缺少的配置是什么?
最佳答案
经过几天的大量调查,问题与CORS issue with Tomcat and Android Webview相同
如上述问题的答案之一所述,添加CordovaOriginWrapper可以解决此问题。
这很棘手,并且离子文件从不谈论这种行为。离子文档需要与此行为进行更新。