I'm trying to use the request
module for Node.js to formulate a HTTPS GET request. The corresponding code using the https
module is as follows:
var https = require('https');
var options = {
hostname: url,
path: path,
rejectUnauthorized: false,
secureProtocol: 'TLSv1_method',
port: 8443,
method: 'POST'
};
https.get(options, function(response) {
var body = '';
response.on('data', function(chunk) {
body += chunk.toString();
});
response.on('end', function() {
var content = JSON.parse(body);
console.log(content);
});
});
I attempted to rewrite this code using the request
module as follows:
var request = require('request');
var options = {
url: url,
strictSSL: false
}
request.get(options, function(error, response, body) {
if (error) {
console.log(error);
} else {
console.log(body);
}
});
However, this gives me an error { [Error: socket hang up] code: 'ECONNRESET', sslError: undefined }
What would be the request
equivalent of rejectUnauthorized: false
?
By setting rejectUnauthorized: false , you're saying "I don't care if I can't verify the server's identity." Obviously this is not a good solution as it leaves you vulnerable to MITM attacks.
This will might help you.
let request = require( 'request' ).defaults({rejectUnauthorized:false});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With