bug: Unknown Error after compiling the application
See original GitHub issueBug Report
Ionic version: [x] 4.x
Current behavior:
Good day. I have an error in HttpClient after compiling the application. When entering the apk it works perfect, but I give login or register does not progress. I was able to extract the error back and the following comes out: {“header”: {“normalizedNames”: {}, “lazyUpdate”: null, “headers”: {}}}, “status”: 0, “statusText”: “unknown error”, “url”: “MY_URL_API” , “ok”: false, “name”: HttpErrorResponse “,” message “:” Http failure response for MY_URL_API: 0 Unknown Error “,” error “: {” isTrusted ": true}}
It should be noted that running ionic serve everything works perfect.
Expected behavior: That works the same as it works in the browser.
Steps to reproduce: The problem is based on the fact that the post, get requests do them perfectly in the browser, but when compiling the app and executing it, it does not perform the actions.
Related code:
login(email: String, password: String) {
const headers = new HttpHeaders({
'Accept': 'application/json'
});
return this.http.post(this.env.API_URL + 'auth/login',
{email: email, password: password}, { headers: headers }
).pipe(
tap(token => {
this.nativeStorage.setItem('token', token)
.then(
() => {
console.log('Token Stored');
},
error => console.error('Error storing item', error)
);
this.token = token;
this.isLoggedIn = true;
return token;
}),
);
}
The problem is that it always returns the following error, but only when running the app on the cell phone or emulator.
{“header”: {“normalizedNames”: {}, “lazyUpdate”: null, “headers”: {}}}, “status”: 0, “statusText”: “unknown error”, “url”: “MY_URL_API” , “ok”: false, “name”: HttpErrorResponse “,” message “:” Http failure response for MY_URL_API: 0 Unknown Error “,” error “: {” isTrusted ": true}}
With Error
Without Error
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
I just found the solution here: https://stackoverflow.com/questions/51902629/how-to-allow-all-network-connection-types-http-and-https-in-android-9-pie
I hope this post is not forgotten. Inside the AndroidManifest.xml add the android tag: usesCleartextTraffic = “true”
<application android: usesCleartextTraffic = “true” . . .>
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.