【问题标题】:Node JS connection establishment between two server两台服务器之间建立Node JS连接
【发布时间】:2018-12-07 15:46:58
【问题描述】:

在我的示例项目中,我使用了 Google recaptcha。我需要在后端(Node JS)验证验证码响应。在 NodeJS 中,我使用了请求模块来连接谷歌服务器。但是,我遇到了一些错误,如下所示

Error: connect ECONNREFUSED 172.217.166.100:443
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)

节点 JS

  formData = {
  secret: 'xxxxxx',
  response: 'yyyyyy'
  }

  request.post({
    url: "https://www.google.com/recaptcha/api/siteverify",
    form: formData
  },
  function (err, httpResponse, body) {
     if (err) throw err;
     if (body) {
       res.send(body);
     }
  });

当我尝试为上面的 NodeJS 代码设置代理时,如下所示...

 formData = {
    secret: 'xxxxxx',
    response: 'yyyyyy'
 }

 request.post({
     url: "https://www.google.com/recaptcha/api/siteverify",
     form: formData,
     proxy: '172.217.166.100' /// Google server IP
 },
 function (err, httpResponse, body) {
   if (err) throw err;
   if (body) {
    res.send(body);
   }
 });

我收到了这些错误......

Error: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:80
at ClientRequest.onError (C:\Users\Desktop\project\Backend\node_modules\tunnel-agent\index.js:177:17)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

谁能帮我解决这个问题

提前致谢

【问题讨论】:

    标签: node.js express npm npm-request


    【解决方案1】:

    看起来你已经指定了类似的东西,

    proxy: '172.217.166.100' /// Google server IP
    

    这是错误的,因为您无法确定谷歌的 IP 地址,因为它是动态的并且经常更改它。

    您可以从以下链接获取最新的代理IP,

    https://code.google.com/archive/p/recaptcha/wikis/FirewallsAndRecaptcha.wiki

    最新的可用 IP 是,

    ip4:216.239.32.0/19 ip4:64.233.160.0/19 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:209.85.128.0/17 ip4:66.102.0.0/20 ip4:74.125.0.0/16 ip4:64.18.0.0/20 ip4:207.126.144.0/20 ip4:173.194.0.0/16

    希望这会有所帮助!

    【讨论】:

    • @Muthukumar 你能看看我上面的更新回复吗?
    • 我已经检查了你更新的回复.....我的问题是在 NodeJS 中,而不是在谷歌服务器 IP 地址中......谷歌验证码响应验证在 POSTMAN 中工作正常......如果我尝试通过 NodeJS 进行验证,我收到了这些错误
    猜你喜欢
    • 2011-01-28
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多