'离子构建android'后,$ http请求在Ionic上失败 [英] $http requests failing on Ionic after 'ionic build android'

查看:149
本文介绍了'离子构建android'后,$ http请求在Ionic上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发过程中,我一直在使用离子服务测试我的应用程序,一切正常。我现在尝试使用离子构建android导出apk,然后将文件'android-debug.apk'存储在我的网络服务器上,并通过手机浏览器下载并安装它以在现实世界中测试它。

I have been testing my app using ionic serve while developing and everything is working fine. I am now trying to export the apk using ionic build android, then storing the file 'android-debug.apk' on my web server and downloading it via a phone's browser and installing it to test it in the real world.

该应用程序安装正常,但不会让我发出任何$ http请求。我已经安装了插件cordova-plugin-whitelist,并且还将以下内容添加到我的config.xml文件中:

The app installs OK, but won't let me make any $http requests. I have installed the plugin cordova-plugin-whitelist, and also added the following to my config.xml file:

    <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文件中:

As well as that, I have added this into my main index.html file:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

有人可以告诉我为什么请求仍然失败了吗?

Can someone tell me why the requests are still failing please?

我已经在2个不同的服务器上进行了测试,两个服务器都启用了CORS,并且已经使用Postman进行了验证。

I have tested on 2 different servers, both have CORS enabled and this has been verified using Postman.

感谢您的帮助

编辑:

我的$ http请求如下所示:

My $http request looks like this:

$http.get('http://url.com/request').then(function(res) {
                    console.log('success');
                    console.log(res);
                }, function(res) {
                    console.log('error');
                    console.log(res);
                });

启用远程chrome调试后,我收到一个错误警告,后面跟一个对象:

After enabling remote chrome debugging, I get an error alert, following by an object which has:

data: null,
status: 0,
statusText: ""


推荐答案

看起来我需要添加:

<uses-permission android:name="android.permission.INTERNET" />

进入platforms / android / AndroidManifest.xml。现在工作正常!

into platforms/android/AndroidManifest.xml. Working OK now!

这篇关于'离子构建android'后,$ http请求在Ionic上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆