-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_client2.js
More file actions
36 lines (29 loc) · 762 Bytes
/
http_client2.js
File metadata and controls
36 lines (29 loc) · 762 Bytes
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
var http = require('http');
var url = process.argv[2];
// console.log("URL: ", url);
http.get(url, function(response) {
response.setEncoding("utf8");
var array = [];
response.on("data", function(data) {
array.push(data)
});
response.on("end", function() {
var str = array.join('');
console.log(str.length);
console.log(str);
});
response.on('error', console.error);
});
/* Alternative mit Buffer List (bl)
var http = require('http')
var bl = require('bl')
http.get(process.argv[2], function (response) {
response.pipe(bl(function (err, data) {
if (err)
return console.error(err)
data = data.toString()
console.log(data.length)
console.log(data)
}))
})
*/