make_request.js
var http = require('http');
exports.makeRequest = function(message){
var options = {
host: 'localhost', port: 8080, path: '/', method: 'post'
};
callback = function(response){
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function(){
console.log(str);
});
};
var request = http.request(options, callback);
request.write(message);
request.end();
};
usage
var mr = require('./make_request.js');
mr.makeRequest("GET_HTML");
//client is request.write();
No comments:
Post a Comment