Http.post error Response with status: 0 for URL: null

let link = ‘http://127.0.0.1:8080/ionic/api.php’;
let data = JSON.stringify({username: “test”});

    this.http.post(link, data)
    .subscribe(data => {
    console.log("ok ");
    }, error => {
        console.log("error : "+error);
    });
3 Likes

I’m having this same problem, only on android… just wasted hours looking for a solution for something that should work out the box. Works just fine on serve

Are you sure your server is getting the request and returning the proper data?

yes, it works just fine with ionic serve, doesn’t work on device

Okay, that makes sense since you’re requesting 127.0.0.1 which is localhost which is only going to work on the server machine. Get the local IP of your server and use that instead (on mac you can do ifconfig). It’ll be something like 192.168.* or 10.0.1.* most likely (could be something else depending on your network). Then make sure your device is on wifi.