鍍金池/ 問(wèn)答/HTML/ request模塊 ETIMEDOUT 的問(wèn)題?

request模塊 ETIMEDOUT 的問(wèn)題?

有一個(gè)請(qǐng)求,在瀏覽器地址欄直接訪問(wèn)是沒(méi)問(wèn)題的,但是用node的request模塊或者h(yuǎn)ttp模塊訪問(wèn),就提示ETIMEDOUT,有人遇到過(guò)這種情況嗎?求指教。

var request = require('request');
var http = require('http');

request.get('http://xxx.xx.xxx.xx:3071/xxx/xxx', (error, response, body) => {
  if (error) {
    console.log(error);
  } else {
    console.log(body);
  }
})

http.get({
  hostname: 'xxx.xx.xxx.xx',
  port: '3071',
  path: '/xxx/xxx'
}, res => {
  console.log(res);
})

request的響應(yīng)

{ Error: connect ETIMEDOUT xxx.xx.xxx.xx:xxxx
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: 'xxx.xx.xxx.xx',
  port: xxxx }
回答
編輯回答
涼薄

排除網(wǎng)絡(luò)原因,應(yīng)該是你訪問(wèn)的地址設(shè)置有驗(yàn)證措施比如UA驗(yàn)證、反爬等等,導(dǎo)致服務(wù)器拒絕響應(yīng)你的請(qǐng)求,地址發(fā)出來(lái)看看,不然也不好測(cè)。

2018年3月16日 22:27
編輯回答
厭遇

防火墻屏蔽端口的問(wèn)題?我也遇到了,正在查

2018年8月20日 08:28