How to make insecure HTTPS call in Node.js

6.9k Views Asked by At

in Curl, I can do -k to perform insecure SSL connections and transfers. However, in node.js, I check the doc for HTTPS. I can't find any options that can do it.

The reason I need this is that I need to call a remote server. I have the cert & passphrase. It can connect. However, since the cert's url is different from the host, the Secure check fail. Well, due to some Operational reason, the cert has to be that way and I'm unable to change it. I have tried putting http.options.hostname be the one same as in the cert. But, it fails as well.

So, what other options I can use?

3

There are 3 best solutions below

0
calca On

The best approach to solve https over insecure SSL certificate it's use a node-curl module and set SSL_VERIFYPEER to false.

var http = require('http');
var curl = require('node-curl');

http.createServer(function(request,response){

    var url = 'https://url';
    url += request.url;

    console.log(url);


    curl(url,
        { 
            SSL_VERIFYPEER : 0
        },
        function(err){
            response.end(this.body);
        })

}).listen(8000);
1
user2996542 On

try rejectUnauthorized in options of https.request

0
Pavel Gavlík On

I haven't been able to get node-curl working, but setting NODE_TLS_REJECT_UNAUTHORIZED env variable to 0 helped. I used the request library to make the HTTPS request.

https://github.com/visionmedia/superagent/issues/205#issuecomment-21669569