-
Notifications
You must be signed in to change notification settings - Fork 1
/
multicaster.js
43 lines (37 loc) · 1.01 KB
/
multicaster.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// multicaster.js
// ==============
var http = require('http');
module.exports = {
get: function(url) {
http.get(url, function(res) {
console.log("Got response: " + res.statusCode);
return res;
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
},
post: function(hostname, port, path, data) {
var options = {
hostname: hostname,
port: port,
path: path,
method: 'POST'
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write(data);
req.end();
}
}
//get("http://www.google.com/index.html");
//post('www.google.com', 80, '/upload', 'helloworld');