【发布时间】:2018-08-07 14:00:31
【问题描述】:
我运行包含以下代码的node myserver.js,40-50 秒后我收到错误(代码以下)。为什么没有发生任何事情时我会收到错误消息?
var options = {
host: 'google.com',
port: '80',
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': 'post_data.length'
}
};
var subscribeRequest = require('http').request(options, function(res) {
console.log('send request');
}).on('error', function(err){console.log(err.stack)});
40-50 秒后出现此错误:
Error: connect ETIMEDOUT
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
【问题讨论】:
-
服务器拒绝您的请求时也会发生这种情况。如果你例如向服务器发出许多请求,它们可能会在一段时间后阻止您并导致此错误。