简体   繁体   English

离子应用程序中对简单节点服务器的 $http 请求抛出“statusText”:“”错误

[英]$http request in ionic app to a simple node server throws “statusText”: “” error

I've stripped down an $http request to the bones and it's still failing without a helpful error message.我已经删除了对骨骼的 $http 请求,但它仍然失败,没有有用的错误消息。 Within my Angular factory I have:在我的 Angular 工厂中,我有:

var url = "http://localhost:3000";
var deferred = $q.defer();

$http.get(url)
  .then(function (success) {
    deferred.resolve(success)
  })
  .catch(function (err) {
    deferred.reject(err)
  })
return deferred.promise;

Inside my node routes I have:在我的节点路由中,我有:

router.get('/', function(req, res, next) {
  res.json({test: 'hi from node index.js'})
});

The full error I'm receiving within my ionic app is:我在 ionic 应用程序中收到的完整错误是:

{
  "data": null,
  "status": -1,
  "config": {
     "method": "GET",
     "transformRequest": [
        null
     ],
     "transformResponse": [
        null
     ],
  "url": "http://localhost:3000",
  "headers": {
     "Accept": "application/json, text/plain, */*"
   }
},
"statusText": ""

I've tried to catch the error inside my node server and I receive我试图在我的节点服务器中捕获错误并且我收到

TypeError: Cannot read property 'type' of undefined

I've disabled cors within my node app.js.我在我的节点 app.js 中禁用了 cors。 I've tried to make a connection with sockets, but still haven't had any luck.我试图与套接字建立连接,但仍然没有任何运气。 I'm running my ionic app with ionic run.我正在使用 ionic run 运行我的 ionic 应用程序。

Any help would be appreciated.任何帮助将不胜感激。 Thanks.谢谢。

Solution: naturally the device has it's own localhost, so when I'm sending an $http.get request from my ionic app, it's not sending it to the same localhost my node server is running on.解决方案:自然,设备有它自己的本地主机,所以当我从我的 ionic 应用程序发送 $http.get 请求时,它不会将它发送到运行节点服务器的同一个本地主机。 The solution is to target your deployed server or your local machine.解决方案是针对您部署的服务器或本地机器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Http 从节点服务器到 Strapi 的请求抛出错误“econnrefused” - Http request from node server to Strapi throws error "econnrefused" 简单的node.js代理通过将http服务器传递给http请求 - Simple node.js proxy by piping http server to http request 为什么 Node.js simple http 服务器应用程序无法在服务器上运行? - Why is Node.js simple http server app not working on server? 非常简单的Node.js客户端在许多http请求之后抛出错误ENOBUFS - Very simple Node.js client throws error ENOBUFS after many http requests 简单的node.js服务器不会错误处理失败的请求 - simple node.js server not error handling failed request 节点服务器的请求路径中的http或https创建错误 - http or https in request path to a node server creates an error 节点服务器中的http请求缓慢 - Slow http request in node server Azure throws error when making an axios http request in node.js API - Azure throws error when making an axios http request in node.js API 在node中,在循环中发布HTTP请求(例如0-10000),将错误抛出为:套接字挂起 - In node , posting HTTP request in loop (say 0 - 10000), Throws error as: Socket hang up 如何制作一个非常简单的 node.js 服务器,它本身会发出 HTTP 请求? - How can I make an incredibly simple node.js server which itself makes an HTTP request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM