Skip to content

Commit 4ee3860

Browse files
author
Nogbit
committed
use request vs. node https.request
1 parent 6717aae commit 4ee3860

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

index.js

+33-18
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var goGetIt = function makeRequest() {
6060

6161
console.log('starting server on https://localhost:4433');
6262

63+
// server
6364
var options = {
6465
key: fs.readFileSync('output/server-key.pem'),
6566
cert: fs.readFileSync('output/server-crt.pem'),
@@ -77,27 +78,41 @@ var goGetIt = function makeRequest() {
7778
res.end("hello world\n");
7879
}).listen(4433);
7980

80-
81-
//now make a request to the server
81+
// client
8282
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+
}
9088
};
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);
9691
});
9792

98-
req.end();
9993

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+
103118
};

0 commit comments

Comments
 (0)