首页 > 解决方案 > Nativescript:未知 URL 的 HTTP 失败响应

问题描述

我有一种情况,我已经从我的分支中提取了最新的更改并尝试使用tns run android命令运行应用程序。该应用程序已成功启动,但 API 调用受到限制,一旦应用程序启动就会引发错误。

我也经历了这个答案,但这似乎不是问题。因为对于其他团队成员来说,它工作正常。:/

    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...

标签: angulartypescriptnativescript

解决方案


从 Android 9.0(API 级别 28)开始,默认情况下禁用明文支持。

android:usesCleartextTraffic使用标志更新清单文件。

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

推荐阅读