Daniel Hutton
Daniel Hutton

Reputation: 1455

$http requests failing on Ionic after 'ionic build android'

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.

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>

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?

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

Thanks for any help

Edit:

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);
                });

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

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

Upvotes: 0

Views: 2137

Answers (1)

Daniel Hutton
Daniel Hutton

Reputation: 1455

Looks like I needed to add:

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

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

Upvotes: 2

Related Questions