我正在尝试循环访问用户并在远程服务器上为每个用户执行请求。许多请求因ECONNREFUSED
错误而失败。我已经尝试设置globalAgent.maxSockets
和交错请求,但问题仍然存在。这是来自远程服务器的响应还是我的节点应用程序中的错误?我该如何解决这个问题?
资源:
var https = require("https");
https.globalAgent.maxSockets = 1024;
var get = function(username, password, cb, failed) {
var post_data = 'username='+user+'&password='+password;
var post_req = https.request({
host:__HOST__,
port:443,
path:'/Controls/CredentialsUI.ashx',
method: "POST",
agent:false,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length
}
}), function(r) {
// get cookie if received
if( r.headers["set-cookie"] )
cb(r.headers["set-cookie"][0].split(";")[0].split("=")[1])
else failed();
});
post_req.on('error', function(error) {
// Error handling here
console.log(error, "for "+username);
});
post_req.write(post_data);
post_req.end();
};
var success = function(){ /*...*/ };
var failure = function(){ /*...*/ };
var users = [/* array about 300 in size */];
users.map(function(user) {
get(user.name, user.password, success, failure);
});