Fetch Api:Can 未从本地主机获取数据

Fetch Api:Can not get data from localhost

我一直在尝试使用 nativescript.I 创建一个 android 应用我正在使用获取模块从我的 server.When 获取响应我正在尝试从 获取响应httpbin.org/get ,它是 OK.But 当我试图从我的本地服务器获得响应时,我收到 Network Request Failed. 错误.

正在发送到 httpbin。org/get-

return fetchModule.fetch("https://httpbin.org/get").then(response => { return response.text(); }).then(function (r) {
        console.log(r);
    }, function (e) {
            console.log(e);
        }); 

发送至localhost:8000/api-

return fetchModule.fetch("http://localhost:8000/api").then(response => { return response.text(); }).then(function (r) {

       console.log(r);

}, function (e) {

        console.log(e);
    });

当我尝试通过请求 module.It 以纯 node.js 的方式从 localhost:8000/api 获得响应时 fine.But 现在,我没有知道如何使用 fetch 模块在 nativescript 中解决这个问题。

相反,localhost(通常 127.0.0.1)使用 10.0.2.2(如果使用 AVD 模拟器)

10.0.2.2  - Special alias to your host loopback interface 
(i.e., 127.0.0.1 on your development machine)

对于 GenyMotion 模拟器,环回地址是 10.0.3.2

模拟器 API 路径:- http://10.0.2.2:5000. Like Your API Local Path Is http://198.168.1:5000/api or http://localhost:5000/api Then Replace With http://10.0.2.2:5000/api 并且端口地址与本地 API 端口相同。

路径- App_resources/Android/src/main/AndroidManifest.xml :-

android:usesCleartextTraffic="true" 在应用标签中添加