Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS requests with rejectUnauthorized as false

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?

like image 934
ashishbaghudana Avatar asked Apr 13 '16 04:04

ashishbaghudana


People also ask

What 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.


1 Answers

This will might help you.

let request = require( 'request' ).defaults({rejectUnauthorized:false});
like image 95
M. Hamza Rajput Avatar answered Sep 20 '22 18:09

M. Hamza Rajput