In this post we will be discussing about how to solve unable to verify the first certificate when doing a post request in Nodejs. Lets say you were using Request module and trying to make https calls, you might end up getting the error "unable to verify the first certificate" because you have not added an appropriate root certificate or you have not added a rejectUnauthorised flag.
Lets take an example :
var request = require("request");
var form = { a: "hello" };
request.post("https://xyz.com", form)
.on('response', function(response) {
if(response.statsusCode === 200) {
// Do Something
}
});
In the above code we are trying to do a post to some https website. If we run this code we will get this error "Error : unable to verify the first certificate".
To fix this issue we will add an appropriate root certificate. ssl-root-cas is a module which will solve node's SSL woes when including a custom certificate. You just need to add require('ssl-root-cas').inject() to your entry point. After this you will not see this error.
If you are trying to do the same thing in your trusted websites or say in your intranet, you can also use the flag rejectUnauthorized and make it false. This will turn off the SLL validation checking but it is not a good idea.
Please Like and Share the CodingDefined.com Blog, if you find it interesting and helpful.
Lets take an example :
var request = require("request");
var form = { a: "hello" };
request.post("https://xyz.com", form)
.on('response', function(response) {
if(response.statsusCode === 200) {
// Do Something
}
});
In the above code we are trying to do a post to some https website. If we run this code we will get this error "Error : unable to verify the first certificate".
To fix this issue we will add an appropriate root certificate. ssl-root-cas is a module which will solve node's SSL woes when including a custom certificate. You just need to add require('ssl-root-cas').inject() to your entry point. After this you will not see this error.
If you are trying to do the same thing in your trusted websites or say in your intranet, you can also use the flag rejectUnauthorized and make it false. This will turn off the SLL validation checking but it is not a good idea.
Please Like and Share the CodingDefined.com Blog, if you find it interesting and helpful.
where is the 'entry point' in the code example above? can you please show the code for the finished working example?
ReplyDeleteI tried this workaround, did not work for me with EWS example
ReplyDeletelulu tobing wikipedia
ReplyDeletehttp://tinyurl.com/z8xrodt facebook esa sigit asli
kebaya pengantin astrid tiar
http://tinyurl.com/y9mnport ratna galih ig
gambar tora sudiro
http://tinyurl.com/yc6bnv39 betharia sonata tak mungkin lagi
I am also getting same error message. If you have sample code then please share this will really help me
ReplyDeleteThis is the example itself, try to post to any https website, you will get the error.
Delete