I am trying to cycle through users and perform a request for each on a remote server. A lot of the requests fail with an ECONNREFUSED
error. I've tried setting globalAgent.maxSockets
and staggering requests but the issue persists. Is this a response from the remote server or an error in my node app? How could I resolve this?
Source:
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);
});