3
我的问题类似于这个问题:Node Js :is it possible to hit 1000 http get request to some api from a node js server但他们的油门解决方案并不适合我。Node.js https获取请求ECONNRESET
我打电话给我们在Google App Engine上托管的api /网站,以触发更新特定产品页面的内存缓存的任务。从async.eachSeries
调用此函数updateCache
。该代码是很简单的:(这是一个消毒版)
function updateCache(object_name, callback) {
var options = {
host : 'www.example.com',
path : '/update-cache/' + object_name,
method : 'GET',
agent : false,
};
var req = https.request(options, function(res) {
res.on('data', function() {
if (res.statusCode !== 200) {
console.log('successful');
}
});
res.on('end', function() {
console.log('end');
callback();
});
});
req.on('error', function(e) {
console.log('failed');
console.error(e.stack);
callback();
});
req.end();
}
它完美地运行我的Mac计算机上,但我需要的脚本使用的是Windows 7在Windows PC上运行,这就是被它得到这个错误:
events.js:141
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:870:11)
at TCP.onread (net.js:552:26)
你有没有看到这个相关的帖子 - http://stackoverflow.com/questions/17245881/node-js-econnreset – ThisClark
我实现了一个解决方案,我发现[stackoverflow](http ://stackoverflow.com/questions/19322248/node-js-distinguishing-errors-when-making-http-request)。到目前为止,我的脚本一直运行良好。 –
我一直在''req.on('timeout',...)中抛出错误,所以我跟着的代码能够捕获错误,但我仍然不知道如何修复超时和连接关闭 –