0

I'm trying to access my web server hosted on http://localhost:8080 on an Angular App built with Cordova. I can access the server with a navigator on my emulator but I never receive any request from the application itself it's just failed with the following error: [objectProgressEvent].

My request is like this and works if I build the web application hosted on localhost:8081:

getToken(username, password) {
        var req = { username: username, password: password };
        this.http.post(this.urlToken, req).toPromise().then((data) => {
            document.getElementById("loader").style.display = "none";
            for (let key in data) {
                this.token = data[key]
                localStorage.setItem('token', this.token);
            }
            if (void this.getIfActiveUser(username) != 84) {
                localStorage.setItem('user', username);
                this.authService.login();
            }
        }).catch((err: HttpErrorResponse) => {
            document.getElementById("loader").style.display = "none";
            this.getIfActiveUser(username)
            console.error('An error occurred:', err.error);
            document.getElementById("warning").style.display = "block";
            if (err.error["non_field_errors"])
                document.getElementById("warning").innerHTML = err.error["non_field_errors"];
            if (err.error["username"])
                document.getElementById("warning").innerHTML = err.error["username"]
            if (err.error["password"])
                document.getElementById("warning").innerHTML = err.error["password"]
        });
}

1 Answer 1

1

Android API doesn't allow clear text communication by default. (CleartextTrafficPermitted) You can check this answer to allow it.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.