Skip to content

Instantly share code, notes, and snippets.

@kitek
Created November 28, 2011 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitek/1400187 to your computer and use it in GitHub Desktop.
Save kitek/1400187 to your computer and use it in GitHub Desktop.
NODE.JS Wysyłanie HTTP POST
var http = require('http');
exports.sendPost = function(options,data,callback) {
var post_data = querystring.stringify(data);
var opts = {
host: options.host,
port: options.port,
maxSockets : 100,
path: options.path,
method: 'POST',
headers: {
'Host': options.host_name,
'Connection' : 'close',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length
}
};
http.globalAgent.maxSockets = 100;
var req = http.request(opts, function(res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
data+=chunk;
});
res.on('end', function () {
if(typeof callback == 'function') {
callback(false,data);
}
});
});
req.on('error', function(e) {
if(typeof callback == 'function') {
callback(e,false);
}
});
req.write(post_data);
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment