Disabling SSL certificate checking in unirest (NodeJS)
Problem:
You want to make a HTTP request with unirest like this:
const unirest = require('unirest');
unirest.get("https://mydomain.net").end(console.log)
but you encounter the following error:
{ error:
{ Error: unable to verify the first certificate
at TLSSocket.<anonymous> (_tls_wrap.js:1088:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:188:7)
at TLSSocket._finishInit (_tls_wrap.js:610:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' } }
Solution
You can work around this problem by using strictSSL(false)
like this:
const unirest = require('unirest');
unirest.get("https://mydomain.net")
.strictSSL(false)
.end(console.log)
Note however that this might have negative effects on the security of your application as this request will be vulnerable to man-in-the-middle attacks.