Response with status: 0 for URL: null


#1

This must be very simple but I am struggling badly with this. My client is very upset over things not working, although rest of the application I’ve completed but because at the login stage only its not working so client is not able to test it.
In browser it works fine but in emulator and device there is this error -

Response with status: 0 for URL: null

On Server side there is CodeIgniter. Searched, tried a lot but could not find a workable solution. Please check codes below and help me resolve the issue.

ionic.config.json

 "proxies": [
    {
      "path": "/login",
      "proxyUrl": "http://www.mydomain.coo/members/login"
    },
    {
      "path": "/update",
      "proxyUrl": "http://www.mydomain.coo/members/update"
    },
    {
      "path": "/register",
      "proxyUrl": "http://www.mydomain.coo/members/register"
    },

login.ts

login() {
    this.showLoader('Authenticating...');
    this.postData = { isApp: '1', key: 'login', email:this.email, password:this.password };

    let data = JSON.stringify(this.postData);

    this.auth.login( this.postData ).then((result) => {

         this.loading.dismiss();

         this.data = result;
         if ( this.data.status == true )
         {
             localStorage.setItem('id', this.data.id);

    this.navCtrl.setRoot(TabsPage);
          }
          else
          {
            this.showLoader('Invalid Credentials...');
            this.loading.present();
            setTimeout(() => {
              this.loading.dismiss();
            }, 2000);
          }

    }, (err) => {
     this.loading.dismiss();
     this.presentToast(err);
    });


  }

auth-service.ts

login(postData) {

    return new Promise((resolve, reject) => {

      let headers = new Headers( {
        'Access-Control-Allow-Origin' : '*',
        'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
        'Content-Type': 'application/json; charset=UTF-8',
        'Accept': 'application/json'
      });

        this.http.post('/login', JSON.stringify(postData), {headers: headers})

        .subscribe(res => {

          resolve(res.json());

        }, (err) => {
          reject(err);
      });



    });


  }

Codeigniter index.php

header(“Access-Control-Allow-Origin: *”);
header(“Access-Control-Allow-Methods: POST, GET, OPTIONS”);
header(“Access-Control-Allow-Headers: X-PINGOTHER, Content-Type”);
header(“Access-Control-Max-Age: 86400”);


#2

I believe proxies in ionic.config.json is only effective during development, not in final builds. I also don’t think you need to be setting all of those headers client-side, and you definitely don’t need to be explicitly instantiating a Promise. Furthermore, if you’re trying this on iOS, I believe all endpoints must be https, not http.


#3

Yes, Service Proxies are a CLI feature, so only work with ionic serve etc on local builds on the same machine.

Did you remote debug the problem on the device already?
Follow these instructions here to debug the problem in Safari dev tools: https://ionic.zone/debug/remote-debug-your-app#ios
Follow these instructions here to debug the problem in Chrome dev tools: https://ionic.zone/debug/remote-debug-your-app#android
Look at the console and network tabs for errors.


#4

Checked similar queries and found no one has given simple straight answer.
I would like to know -
I have done is correct or not?
How have you done the same if its working for you?


#5

What does that mean?

On a build that should work outside of your local machine you can’t use Service Proxies, you hav to use the proper URL of the API directly.