简体   繁体   English

nodeJS 请求 POST To localhost:3000 ECONNREFUSED

[英]nodeJS request POST To localhost:3000 ECONNREFUSED

At one point I just want to make a POST request to my rails server running on localhost:3000有一次我只想向在localhost:3000上运行的rails服务器发出POST请求

If a use like postman on even cUrl I can ping my API如果像postman一样在cUrl上使用,我可以 ping 我的 API

But kow, with my node app I want to do this:但是,哇,我想用我的节点应用程序来做到这一点:

    var req_body = {
       'my_id': id,
        'dataTable': data }


    var options = {
       method:   'POST',
       url:      config.get('api_url') + 'end_tracking',
       json:     true,
       body:     req_body
      }
      //  config.get('api_url') return http://localhost:3000/

      request(options, function (error, response, body) {
                console.log(error)
    ... }

this is what I get:这就是我得到的:

{ Error: connect ECONNREFUSED 127.0.0.1:3000
at Object.exports._errnoException (util.js:896:11)
at exports._exceptionWithHostPort (util.js:919:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1073:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3000 }

and as I said, if I do this request directly with postman, everything works !正如我所说,如果我直接向邮递员提出这个请求,一切正常!

I finally did it !我终于做到了!

For a unknown reason, accessing localhost:3000 , launched with rails s didn't work at all on my node server出于未知原因,访问localhost:3000 ,使用rails s启动在我的节点服务器上根本不起作用

but I worked when I started the rails server with rails s -b 0.0.0.0 !但是当我用rails s -b 0.0.0.0启动 rails 服务器时我工作了!

how i did this, just use the same structure and i hope it works for you我是怎么做到的,只是使用相同的结构,我希望它对你有用

request({
        url: url, //URL to hit
        method: 'post',
        headers: headers,
        timeout: 10000,
        body: JSON.stringify(body)
    }, function (error, result, body) {
        if (error) {
           console.log(error);
        } else if (result.statusCode == 500) {
            console.log('not found');
        } else {
            console.log('success')
        }
    });

hope it works.希望它有效。

暂无
暂无

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

相关问题 nodejs 请求模块在本地主机上返回 ECONNREFUSED - nodejs request module returning ECONNREFUSED on localhost NextJS/Vercel/MongoDB FetchError:对 http://localhost:3000/api/gear 的请求失败,原因:连接 ECONNREFUSED 127.0.0.1:3000 - NextJS/Vercel/MongoDB FetchError: request to http://localhost:3000/api/gear failed, reason: connect ECONNREFUSED 127.0.0.1:3000 React 代理错误:无法代理请求 /api/ 从 localhost:3000 到 http://localhost:8000 (ECONNREFUSED) - React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED) FetchError:请求http:// localhost:3000 / api / projects失败,原因:connect ECONNREFUSED 127.0.0.1:3000(Express / Next.Js) - FetchError: request to http://localhost:3000/api/projects failed, reason: connect ECONNREFUSED 127.0.0.1:3000 (Express/Next.Js) POST http://localhost:3000/api/customers 404(未找到)reactjs nodejs - POST http://localhost:3000/api/customers 404 (Not Found) reactjs nodejs 在 ejs 和 nodejs 中发布 http://localhost:3000/socket.io/?EIO=3&transport=polling&t=NQUneY3 400(错误请求) - POST http://localhost:3000/socket.io/?EIO=3&transport=polling&t=NQUneY3 400 (Bad Request) in ejs and nodejs 使用 Nodejs 连接 ECONNREFUSED 127.0.0.1:3000 - DB Mongoose - connect ECONNREFUSED 127.0.0.1:3000 - DB Mongoose with Nodejs “React 代理错误:无法将请求 /api/ 从 localhost:3000 代理到 http://localhost:5000 (ECONNREFUSED)”?错误.. 没有在线解决方案 - "React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:5000 (ECONNREFUSED)'? Error.. No solution online nodejs请求ECONNREFUSED - nodejs request ECONNREFUSED POST http://localhost:3000/updateSurvey 400(错误请求) - POST http://localhost:3000/updateSurvey 400 (Bad Request)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM