Unable to Make API Call on Ionic 2 Android App

Hi,

I am unable to make API call on Ionic 2 Android App, but it works well on a browser. I have tried all possible methods answered on this forum, stackoverflow etc. but couldn’t find any working solutions.

The below methods are done, but none of them worked

  • Adding a proxy to ionic.config.js
  • Cordova whitelist
  • Adding cros to config.xml

My endpoint is at http://calorie-api.wlabs.xyz/login – this endpoint except a phone with 10 digit mobile number. And the below is the login.ts

  login(a) {
let loading = this.loadingCtrl.create({
  content: 'Please wait...'
});

let prompt = this.alertCtrl.create({
  title: 'Enter the OTP',
  inputs: [{
    name: 'OTP',
    placeholder: 'OTP'
  },
  ],
  buttons: [{
    text: 'Cancel',
    handler: data => {
      console.log('Canceled');
    }
  }, {
    text: 'submit',
    handler: data => {
      console.log('OTP');
    }
  }]
});

let failed = this.alertCtrl.create({
  subTitle: 'Something went wrong, please try again.',
  buttons: ['Dismiss']
});

loading.present();

let body = new FormData()
body.append('phone', a);

this.http.post('http://calorie-api.wlabs.xyz/login', body)
  .subscribe(data => {
    loading.dismiss();
    prompt.present();
  }, error => {
    loading.dismiss();
    failed.present();
  });  }

Please do help me out before I tear my hairs apart :stuck_out_tongue: