小编Asm*_*man的帖子

获取Api:无法从localhost获取数据

我一直在尝试使用nativescript创建一个Android应用程序.我正在使用fetch模块从我的服务器获取响应.当我试图从httpbin.org/get获得响应时,它没关系.但是当我试图获得响应时从我的本地服务器,我收到网络请求失败.错误.

发送到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);
        }); 
Run Code Online (Sandbox Code Playgroud)

发送到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);
    });
Run Code Online (Sandbox Code Playgroud)

当我尝试通过请求模块从localhost:8000/api获取纯node.js的响应.它工作正常.但是现在,我不知道如何使用fetch模块在nativescript中解决这个问题.

android node.js nativescript fetch-api laravel-5.2

3
推荐指数
1
解决办法
2666
查看次数

标签 统计

android ×1

fetch-api ×1

laravel-5.2 ×1

nativescript ×1

node.js ×1