7

I wanted to make simple POST HTTP request by using request module:

var request = require("request");
var form = {form: {some: "form", attributes: "attrs"}}
request.post("https://example.com", form)
   .on('response', function(response) {

   if (response.statusCode === 200) {
     console.log("DONE");
   } else {
     console.log("FAIL");
   }
});

When I launch this code it throws me this error message:

Error: unable to verify the first certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1057:38)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket._finishInit (_tls_wrap.js:596:8)

I think this is happening because url has https, but I don't know how to fix this error.

How to disable checking certificate?

Mr.D
  • 7,353
  • 13
  • 60
  • 119
  • 2
    Possible duplicate of [Error: unable to verify the first certificate in nodejs](http://stackoverflow.com/questions/31673587/error-unable-to-verify-the-first-certificate-in-nodejs) – CodingDefined Mar 24 '16 at 08:33

2 Answers2

6

Add "rejectUnauthorized": false as option:

request.post({url: "https://example.com", "rejectUnauthorized": false}, form)
   .on('response', function(response) {

   if (response.statusCode === 200) {
     console.log("DONE");
   } else {
     console.log("FAIL");
   }
});

Or add the appropiate certificate via https://www.npmjs.com/package/ssl-root-cas

require('ssl-root-cas').inject();
michelem
  • 14,430
  • 5
  • 50
  • 66
  • When I use your code, it throws me `Error: Invalid URI "/"` error message. – Mr.D Mar 24 '16 at 06:45
  • Try `request.post({uri: "https://example.com", rejectUnauthorized: false}` but it should be the same – michelem Mar 24 '16 at 06:46
  • 1
    I changed as you asked, It still throws `Error: Invalid URI "/"` error. – Mr.D Mar 24 '16 at 07:21
  • 10
    Disabling the cert verification is potentially dangerous and definitely NOT a good solution, a workaround at best but a massive security flaw in most cases. – 0x1gene Oct 26 '16 at 14:10
0

You can try with disabling ssl certificate verification under File->Settings Settings image

FJJ
  • 49
  • 2