【发布时间】:2015-08-11 08:40:08
【问题描述】:
我在开发过程中一直在使用 ionic serve 测试我的应用程序,一切正常。我现在正在尝试使用 ionic build android 导出 apk,然后将文件“android-debug.apk”存储在我的网络服务器上,并通过手机的浏览器下载并安装它以在现实世界中进行测试。
应用程序安装正常,但不允许我发出任何 $http 请求。我已经安装了插件 cordova-plugin-whitelist,并且还在我的 config.xml 文件中添加了以下内容:
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<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>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
除此之外,我已将其添加到我的主 index.html 文件中:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
谁能告诉我为什么请求仍然失败?
我已经在 2 台不同的服务器上进行了测试,都启用了 CORS,并且已经使用 Postman 进行了验证。
感谢您的帮助
编辑:
我的 $http 请求如下所示:
$http.get('http://url.com/request').then(function(res) {
console.log('success');
console.log(res);
}, function(res) {
console.log('error');
console.log(res);
});
启用远程 chrome 调试后,我收到一个错误警报,后面跟着一个对象:
data: null,
status: 0,
statusText: ""
【问题讨论】:
-
您可以使用 chrome 检查混合应用程序,它可以向您显示错误。将您的手机连接到您的系统并检查应用程序。
-
我刚试过,我得到的错误是:
POST: http//url.com net::ERR_CACHE_MISS...虽然没有提供更多信息 -
在网络选项卡中,请求显示
(failed) xhr -
复制 url 并尝试通过系统中的邮递员运行它。看看你能不能得到回应。
标签: android angularjs cordova ionic-framework ionic