Native HTTP not working on native android app


#1

I’m having difficulties with native HTTP when I run my app as a native android app.

          this.native.get(env.api.native.url + 'quotes', params, this.NATIVE_HEADER)
            .then((res: HTTPResponse) => {
              if (res.status === 200) {
                resolve(res.data)
              } else {
                reject({ from: 'this.native.get.res.status != 200', res })
              }
            })
            .catch((error: any) => {
              reject({ from: 'this.native.get.catch', error })
            })

I’m getting this error (in the native.get.catch()):

{
  "from": "this.native.get.catch",
  "error": {
    "__zone_symbol__currentTask": {
      "type": "microTask",
      "state": "notScheduled",
      "source": "Promise.then",
      "zone": "angular",
      "cancelFn": null,
      "runCount": 0
    }
  }
}

The problem does NOT occur when I run ionic serve -c and run the app through Ionic DevApp.

Any help would be greatly appreciated. Thx.


#2

My first guess would be that this variable is not set correctly.


#3

Thanks for your reply. I ended up going with a pure HttpClient solution which I was able to get working once I tweaked my API to respond with the right Access-Control-Allow-Origin header.


#4

Glad you found a solution. I prefer Javascript native fetch() myself.