File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 1+ var http = require ( "http" ) ;
2+
3+ var options = {
4+ 'host' :'127.0.0.1' ,
5+ 'port' :'1234' ,
6+ 'path' :'/new.txt'
7+ }
8+
9+ var callback = function ( response ) {
10+
11+ var data = "" ;
12+
13+ response . on ( 'data' , function ( val ) {
14+ data += val ;
15+ } ) ;
16+ response . on ( 'end' , function ( ) {
17+ console . log ( data ) ;
18+ } ) ;
19+ } ;
20+
21+ var req = http . request ( options , callback ) ;
22+ req . end ( ) ;
23+
24+ // var http = require('http');
25+
26+ // // Options to be used by request
27+ // var options = {
28+ // host: 'localhost',
29+ // port: '1234',
30+ // path: '/new.txt'
31+ // };
32+
33+ // // Callback function is used to deal with response
34+ // var callback = function(response){
35+ // // Continuously update stream with data
36+ // var body = '';
37+ // response.on('data', function(data) {
38+ // body += data;
39+ // });
40+
41+ // response.on('end', function() {
42+ // // Data received completely.
43+ // console.log(body);
44+ // });
45+ // }
46+ // // Make a request to the server
47+ // var req = http.request(options, callback);
48+ // req.end();
Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ http.createServer(function(req,res){
2121 res . write ( data . toString ( ) ) ;
2222 }
2323 res . end ( ) ;
24-
2524 } )
2625
2726} ) . listen ( 1234 ) ;
You can’t perform that action at this time.
0 commit comments