Nativescript: HTTP failure response for unknown URL

Viewed 3176

I have a situation, I have pulled the latest changes from my branch and trying to run the application using tns run android command. The app is launched successfully but the API call is restricted throwing an error as soon as the app starts.

I have also gone through this answer but that's not the problem it seems. Because for other team members it is working fine. :/

    err {
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null,
JS:     "headers": {}
JS:   },
JS:   "status": 0,
JS:   "statusText": "Unknown Error",
JS:   "url": null,
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure response for (unknown url): 0 Unknown Error",
JS:   "error": {
JS:     "originalStack": "Error: java.io.IOException: Cleartext HTTP traffic to elk.chennai-volunteer-294695.staging.c66.me not permitted\n    at new ZoneAwareError (file:///data/data/org.nativescript.chennaivolunteersapp/files/app/
tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:1298:33)\n    at onRequestComplete (file:///data/data/org.nativescript.chennaivolunteersapp/files/app/tns_modules/tns-core-modules/http/http-request/http-request.js:
45:34)\n    at Object.onComplete (file:///data/data/org.nativescript.chennaivolunteersapp/files/app/tns_modules/tns-core-modules/http/http-request/http-request.js:37:13)",
JS:     "zoneAwareStack": "Error: java.io.IOException: Cleartext HTTP traffic to elk.chennai-volunteer-294...
2 Answers

Starting with Android 9.0 (API level 28), cleartext support is disabled by default.

Update your manifest file with the android:usesCleartextTraffic flag.

<application ... android:usesCleartextTraffic="true" ...>

Go to: your-project\App_Resources\Android\src\main\AndroidManifest.xml

Update your manifest by adding android:usesCleartextTraffic="true" to existing rules in <application></application> tag, like as seen bellow

<application
    ...
    ...
    android:usesCleartextTraffic="true"
    ...
    ...
</application>
Related