两个服务器之间的节点JS连接建立

时间:2018-12-07 06:46:27

标签: node.js express npm npm-request

在我的示例项目中,我使用了Google Recaptcha。我需要验证后端(节点JS)的验证码响应。在NodeJS中,我使用了请求模块来与Google服务器连接。但是,我遇到了类似以下的错误

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)

Node 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)

任何人都可以帮助我解决此问题

预先感谢

1 个答案:

答案 0 :(得分:0)

看起来您已经指定了类似的内容,

proxy: '172.217.166.100' /// Google server IP

这是错误的,因为您不能确定google的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

希望这会有所帮助!