Request: Make HTTPS call from request module

Created on 8 Jan 2017  ·  12Comments  ·  Source: request/request

I'm trying to make https call using request module, below is current existing options
and i have pfx file and password.

strictSSL: false,
rejectUnauthorized: false,
agent: false

Can somebody help me out about what all need to be set as true and do i need to export cert files.

If possible please share openssl command for this.

I tried exporting cert and made strictSSL and rejectUnauthorized true, but end up seeing error like

message: 'Error: unable to verify the first certificate'

Node Version is 6.9.2

stale

Most helpful comment

For a workaround, disable the requirement that SSL certificates must be valid and bypass altogether. Add "strictSSL: false" as such:

{  
   url: "https://...",
   method: "POST",
   headers: {
        "Content-Type": "application/json"},
   strictSSL: false
}

All 12 comments

Did you try by setting
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'

@rpgeeganage this is not a preferred way.

Full error stack

{ Error: unable to verify the first certificate
    at Error (native)
    at TLSSocket.<anonymous> (_tls_wrap.js:1085:38)
    at emitNone (events.js:86:13)
    at TLSSocket.emit (events.js:185:7)
    at TLSSocket._finishInit (_tls_wrap.js:603:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:433:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' } 'error'

I have encountered this issue too. Did you find a workaround @tomalex0 ?

Any update on this?

I have come across this issue as well.

For a workaround, disable the requirement that SSL certificates must be valid and bypass altogether. Add "strictSSL: false" as such:

{  
   url: "https://...",
   method: "POST",
   headers: {
        "Content-Type": "application/json"},
   strictSSL: false
}

My server is in a private network (no Internet access) and it should work there and I signed the certificate and trust it with own CA...I get the UNABLE_TO_VERIFY_LEAF_SIGNATURE error even when I add the ca.pem file to the options.agentOptions.ca. What should I do to fix this error obviously without disabling the strictSSL option or any other unsafe options?

In my case, an SSL certificate I generated with LetsEncrypt works fine with node https library or with the request library. However, using the same cert off port 443 (which works fine from the Golang components of my system and works fine in Chrome) completely chokes Node's https library and the request library, both with the same error. I'm still trying to understand what's going wrong here, but for at least this case, these root CA hacks seem not to work.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

no one to follow so close it and pretend it never happen ?
my URL is working fine with all browser but not "request.js"

I was getting same error. Fixed by marking strictSSL as false, below code worked for me.
var client = new RestClient({
connection: {
pfx: fs.readFileSync(certFile),
passphrase: certPassword,
strictSSL: false,
rejectUnauthorized: false,
agent: false
}
});

I am using node rest client architecture for my API.

Hope this might help anyone looking for similar fix

Try this:
var request = require("request").defaults({rejectUnauthorized:false});

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mlegenhausen picture mlegenhausen  ·  4Comments

xin7c picture xin7c  ·  3Comments

Aranir picture Aranir  ·  3Comments

jasonxia23 picture jasonxia23  ·  3Comments

crostine picture crostine  ·  3Comments