Cant make HTTP(S) calls from DevApp - Error is [object Object]

Hi. I have been stuck for over a day now trying to make HTTP and HTTPS calls from my Ionic 3 App running in Ionic DevApp on my Android phone. I am running ionic serve -c and running the app in both Chrome browser on my PC and in DevApp. No matter what I do the call always returns an error with the data [object Object]

Chrome wasn’t working until I enabled CORS on my server by changing the config of my .NET WebAPI project. Now calls work fine from Chrome.

I have tried both HttpClient from ‘@angular/common/http’ and HTTP from ‘@ionic-native/http’ (the second of which isn’t usable in Chrome being a Cordova component), but neither work within the DevApp. These are the methods:

private getString1(httpClient: HttpClient, callbackUrl : string) : Promise<any> {
    return new Promise(resolve => {              
        httpClient.get(callbackUrl).subscribe(data => {
        console.log(data);  // Chrome gets string from server
        resolve(data);
      }, err => {
        console.log("Error - ", err); // DevApp gets [object Object]
        });      
    });
  }

  private getString2(http : HTTP, callbackUrl : string) : void {
    this.http.get(callbackUrl, {}, {}).then(data => {
      console.log(data);  // Chrome gets string from server
    }).catch(error => {
      console.log("Error - " + error);  // DevApp gets [object Object]
    });
  }

Finally I have added this to ionic.config.json to create a proxy:

{
  "name": "xxxxx",
  "integrations": {
    "cordova": {}
  },
  "type": "ionic-angular",
  "proxies": [
    {
      "path": "/api/auth",
      "proxyUrl": "http://localhost:64279/api/auth" }
  ]
}

and changed the HTTP addresses to localhost:8100…to no avail.

I am pretty much out of ideas at this point. I need to use DevApp for development rather than Chrome as I need @ionic-native/in-app-browser to implement oAuth 2.0 workflow. I can probably just develop in Chrome and work around this somehow, but it would be nice to test the app as it will be used. I am also worried this isn’t just a DevApp issue, but wont work when I publish the app.

As per your problem statement Just I’m thinking you can enable CORS on your dev env too. If this is enabled already check with the method what you are getting error in backend once. If you are getting response from server but contains error seems from server end.

I am not really sure what you mean. I was able to get things working briefly using Fiddler as a proxy…but unfortunately it didn’t last and things stopped working for no obvious reason. I am losing faith in Ionic at this point I have to say.

Hey, @mrlane

You need to connect your api via ip address.
So if your api_url is localhost:3000/api/v1, you must change it to your PC ip eg. 192. 168.10.1:3000/api/v1

DevApp doesn’t seem to know how to handle “localhost”.

Any luck with this. I’m getting the same. Works fine in browser. But in devapp, I my httpClient fails, and I see [object object]. Not sure how to borrow into the error since it doesn’t fail on chrome where I could get a better look at hte object.

EDIT

Have built the project in Android and run it directly ont he device. Exact same failure. So, like I said before, is there some problwm with httpClient? What plugins are needed to use it on a real device? Seriously, a little help. Looks like this has been a problme for nearly a year. Ionic is bleeding developer over nonsense like this. If it works, great. Just please tell us how.

Can i just add, I really don’t understand this line of approach. Isn’t CORS only an issue for the browser. The error is that http requests aren’t working in devapp. Isn’t it more likely that there’s some cordova plugin missing, or some setup required in android platform first. I don’t know. If I did, I would fix it…

Just try the IP address approach and see how it goes.
LOCALHOST will NOT WORK!

Any solutions i am facing the same problem, i changed localhost to 127.0.0.1 still not working

My solution in the end was to switch to Xamarin.