@@ -60,6 +60,7 @@ var goGetIt = function makeRequest() {
60
60
61
61
console . log ( 'starting server on https://localhost:4433' ) ;
62
62
63
+ // server
63
64
var options = {
64
65
key : fs . readFileSync ( 'output/server-key.pem' ) ,
65
66
cert : fs . readFileSync ( 'output/server-crt.pem' ) ,
@@ -77,27 +78,41 @@ var goGetIt = function makeRequest() {
77
78
res . end ( "hello world\n" ) ;
78
79
} ) . listen ( 4433 ) ;
79
80
80
-
81
- //now make a request to the server
81
+ // client
82
82
var reqOptions = {
83
- hostname : 'localhost' ,
84
- port : 4433 ,
85
- path : '/' ,
86
- method : 'GET' ,
87
- key : fs . readFileSync ( 'output/client-key.pem' ) ,
88
- cert : fs . readFileSync ( 'output/client-crt.pem' ) ,
89
- ca : fs . readFileSync ( 'output/ca-crt.pem' )
83
+ url : 'https://localhost:4433' ,
84
+ agentOptions : {
85
+ cert : fs . readFileSync ( 'output/client-crt.pem' ) ,
86
+ key : fs . readFileSync ( 'output/client-key.pem' )
87
+ }
90
88
} ;
91
-
92
- var req = https . request ( reqOptions , function ( res ) {
93
- res . on ( 'data' , function ( data ) {
94
- process . stdout . write ( data ) ;
95
- } ) ;
89
+ request . get ( reqOptions , function ( error , response , body ) {
90
+ console . log ( body ) ;
96
91
} ) ;
97
92
98
- req . end ( ) ;
99
93
100
- req . on ( 'error' , function ( e ) {
101
- console . error ( e ) ;
102
- } ) ;
94
+ // Use node https.request vs. request module
95
+ // This works as well
96
+ //
97
+ // var reqOptions = {
98
+ // hostname: 'localhost',
99
+ // port: 4433,
100
+ // path: '/',
101
+ // method: 'GET',
102
+ // key: fs.readFileSync('output/client-key.pem'),
103
+ // cert: fs.readFileSync('output/client-crt.pem')
104
+ // };
105
+
106
+ // var req = https.request(reqOptions, function(res) {
107
+ // res.on('data', function(data) {
108
+ // process.stdout.write(data);
109
+ // });
110
+ // });
111
+
112
+ // req.end();
113
+
114
+ // req.on('error', function(e) {
115
+ // console.error(e);
116
+ // });
117
+
103
118
} ;
0 commit comments