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


#1

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.


#2

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.


#3

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.