# External api resource not working on android device using http

**URL:** <https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260>\
**Category:** ionic-v1\
**Created:** [July 14, 2015, 12:55am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260 "2015-07-14T00:55:39Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![danboh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/danboh/32/90610_2.png) [@danboh](https://forum.ionicframework.com/u/danboh)\
**Post date:** [July 14, 2015, 12:55am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/1 "2015-07-14T00:55:39Z")

</div>

I’ve started developing my first mobile app (loving the framework so far!). However, I’m facing some issues when it comes to retrieving data from my remote server. Mind you, these issues are NOT occurring when using `ionic serve` or `ionic run android -l`, but they do when you do `ionic run android` or when running in ionic view.

I’ve already added the cordova whitelists to the project by running `cordova plugin add cordova-plugin-whitelist`

Here’s my controller.js

```
function search(map) {

    var searchParamenters = ''text=1";

var request = $http({
    method: "post",
    url: "/php/mobileSearch.php",
    data: searchParamenters,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    timeout: 10000
}).success(function( data ) {
    console.log(data.length);
}).
error(function(data, status, headers, config) {
    alert('Error retrieving data from server: '+status);
        $ionicLoading.hide();
    });
};

```

My ionic.project:

```
 {
      "name": "RealEstate",
      "app_id": "fb5db279",
      "proxies": [
        {
          "path": "/php/mobileSearch.php",
          "proxyUrl": "http://my.domain.com/php/mobileSearch.php"
        }
      ]
    }

```

My config.xml includes:

```
<allow-navigation href="*"/>

```

http always goes to error and the results of the data object in the error section is 0

Thoguhts? Ideas? Suggestions?

---

<div class="post-metadata">

**Author:** ![mrameezraja](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mrameezraja/32/12745_2.png) [@mrameezraja](https://forum.ionicframework.com/u/mrameezraja)\
**Post date:** [July 14, 2015, 6:57am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/2 "2015-07-14T06:57:04Z")

</div>

Also add a meta tag in head section.

```
 <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-eval' 'unsafe-inline' https://*.googleapis.com http://*.google.com https://*.gstatic.com http://*.gstatic.com ">
```

---

<div class="post-metadata">

**Author:** ![danboh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/danboh/32/90610_2.png) [@danboh](https://forum.ionicframework.com/u/danboh)\
**Post date:** [July 14, 2015, 12:49pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/3 "2015-07-14T12:49:12Z")

</div>

Thanks for the reply, but adding

```
 <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-eval' 'unsafe-inline' https://*.googleapis.com http://*.google.com https://*.gstatic.com http://*.gstatic.com ">

```

doesn’t making a difference, still failing…

---

<div class="post-metadata">

**Author:** ![mrameezraja](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mrameezraja/32/12745_2.png) [@mrameezraja](https://forum.ionicframework.com/u/mrameezraja)\
**Post date:** [July 15, 2015, 8:44am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/4 "2015-07-15T08:44:51Z")

</div>

Did you add your url in meta tag and `<access origin="*" subdomains="true"/>` in config.xml ?

---

<div class="post-metadata">

**Author:** ![danboh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/danboh/32/90610_2.png) [@danboh](https://forum.ionicframework.com/u/danboh)\
**Post date:** [July 15, 2015, 12:31pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/5 "2015-07-15T12:31:38Z")

</div>

> [@mrameezraja](#):
>
> \<access origin=“\*” subdomains=“true”/\>

I just tried it and same results

---

<div class="post-metadata">

**Author:** ![danboh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/danboh/32/90610_2.png) [@danboh](https://forum.ionicframework.com/u/danboh)\
**Post date:** [July 21, 2015, 5:10am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/6 "2015-07-21T05:10:07Z")

</div>

Still unable to retrieve data from my server from my device (however it works perfectly on browser).

I’ve updated my index.html to include:

```
<meta http-equiv="Content-Security-Policy" content="default-src *;
               script-src &apos;self&apos; &apos;unsafe-inline&apos; &apos;unsafe-eval&apos;
                           127.0.0.1:*
                           http://localhost:*
                           http://*.gstatic.com
                           https://*.googleapis.com
                           https://*.gstatic.com
                           https://*.googleapis.com
                           http://www.mydomain.ca
                           ;
               style-src &apos;self&apos; &apos;unsafe-inline&apos;
                           127.0.0.1
                           http://localhost:*
                           http://*.gstatic.com
                           https://*.googleapis.com
                           https://*.gstatic.com
                           https://*.googleapis.com
                           http://www.mydomain.ca
        ">
```

---

<div class="post-metadata">

**Author:** ![bengtler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bengtler/32/98565_2.png) [@bengtler](https://forum.ionicframework.com/u/bengtler)\
**Post date:** [July 21, 2015, 6:21am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/7 "2015-07-21T06:21:27Z")

</div>

and you added the whitelist plugin to your project?

---

<div class="post-metadata">

**Author:** ![danboh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/danboh/32/90610_2.png) [@danboh](https://forum.ionicframework.com/u/danboh)\
**Post date:** [July 21, 2015, 12:28pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/8 "2015-07-21T12:28:10Z")

</div>

That’s correct @bengtler

---

<div class="post-metadata">

**Author:** ![kvss](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@kvss](https://forum.ionicframework.com/u/kvss)\
**Post date:** [July 22, 2015, 6:25pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/9 "2015-07-22T18:25:47Z")

</div>

Very frustrating. I have the same exact problem. The app works great in ionic serve, the ios simulator, android emulator, and my iPhone, but does not work at all on HTC M9 or any other Android device. I updated cordova and installed the most recent whitelist plugin. I added

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

```

at the top of my index file and have

```
<access origin="*"/>

```

in my config.xml file. Any other ideas out there?

---

<div class="post-metadata">

**Author:** ![danboh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/danboh/32/90610_2.png) [@danboh](https://forum.ionicframework.com/u/danboh)\
**Post date:** [July 22, 2015, 6:44pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/10 "2015-07-22T18:44:53Z")

</div>

Glad to know I’m not the only one!! But it sucks this is not getting enough attention ☹

---

<div class="post-metadata">

**Author:** ![swade](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@swade](https://forum.ionicframework.com/u/swade)\
**Post date:** [July 22, 2015, 8:01pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/11 "2015-07-22T20:01:17Z")

</div>

I found an answer elsewhere to add:

`<allow-navigation href="http://*/*" />`

Worked for me.

---

<div class="post-metadata">

**Author:** ![danboh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/danboh/32/90610_2.png) [@danboh](https://forum.ionicframework.com/u/danboh)\
**Post date:** [July 25, 2015, 4:01pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/12 "2015-07-25T16:01:25Z")

</div>

> [@swade](#):
>
> \<allow-navigation href=“http://_/_” /\>

Thanks Swade, but that did not solve my problem ☹

---

<div class="post-metadata">

**Author:** ![akash21](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/akash21/32/90679_2.png) [@akash21](https://forum.ionicframework.com/u/akash21)\
**Post date:** [July 26, 2015, 6:19am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/13 "2015-07-26T06:19:31Z")

</div>

I’m having the exact same issue ever since I updated cordova to latest version. Used to work fine before. My thread: [External api resource not working on android device using http](http://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260)

---

<div class="post-metadata">

**Author:** ![akash21](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/akash21/32/90679_2.png) [@akash21](https://forum.ionicframework.com/u/akash21)\
**Post date:** [July 26, 2015, 8:01am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/14 "2015-07-26T08:01:48Z")

</div>

Guys I solved it by having these permissions in AndroidManifest.xml file:

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

```

It might help some of you 🙂

---

<div class="post-metadata">

**Author:** ![danboh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/danboh/32/90610_2.png) [@danboh](https://forum.ionicframework.com/u/danboh)\
**Post date:** [July 29, 2015, 12:22am UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/15 "2015-07-29T00:22:51Z")

</div>

I was able to resolve the issue by NOT using proxies in the ionic.project file as recommended by Ioninc, instead I call the resource using the full URL in my controller.

---

<div class="post-metadata">

**Author:** ![fcoaldunate](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@fcoaldunate](https://forum.ionicframework.com/u/fcoaldunate)\
**Post date:** [May 12, 2016, 3:22pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/16 "2016-05-12T15:22:46Z")

</div>

I have the same problem in Android (IOS is working), but I use ngResource with absolute url. I tried all the possibilities discussed above without good results.

some idea or suggestion?

---

<div class="post-metadata">

**Author:** ![lmarcelocc](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@lmarcelocc](https://forum.ionicframework.com/u/lmarcelocc)\
**Post date:** [August 10, 2017, 2:20pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/17 "2017-08-10T14:20:42Z")

</div>

Worked for me. Thanks!

---

<div class="post-metadata">

**Author:** ![akcaravindh](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@akcaravindh](https://forum.ionicframework.com/u/akcaravindh)\
**Post date:** [June 1, 2020, 6:30pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/18 "2020-06-01T18:30:45Z")

</div>

Open **“resources/android/xml/network\_security\_config.xml”** and update your domain instead of localhost

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 8:54pm UTC](https://forum.ionicframework.com/t/external-api-resource-not-working-on-android-device-using-http/28260/19 "2021-07-19T20:54:37Z")

</div>


