我已经提到https://github.com/apache/cordova-plugin-whitelist及以下添加到我的config.xml:http请求离子构建Android后未能
<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链接,我可以从应用程序访问这些网站。
通过运行“离子发球”来运行web应用程序非常好。从Android apk中,没有任何请求触及服务器。
什么是缺少的配置?
嘿,你有没有找到解决你的问题?我在这里有类似的情况:http://stackoverflow.com/questions/40870757/ionic-app-on-android-not-sending-http-requests – Bndr
在进一步的调查中,我看到我的请求命中Tomcat服务器,但被拒绝与403.然后我遇到了这个问题:http://stackoverflow.com/questions/23224508/cors-issue-with-tomcat-and-android-webview现在按照上述问题中的步骤来解决我的问题。 – user170008