问题
I am using request-promise module for my node app to make some API call. https://www.npmjs.com/package/request-promise
import request from 'request-promise';
let options = {
method: GET,
json: true,
uri : "https://" +this.urls + endpoint,
body: payload,
rejectUnauthorized: false // This doesn't work
};
let response = await request(options)
SInce the API what I am trying to use is insecure (having self signed certificate), the conncetion is failing with this error:
Error: connect ECONNREFUSED
I know with "request" module, we could pass rejectUnauthorized: false , to handle such case. I am not sure how can I pass such option with request-promise module.
回答1:
Try adding this to top of your code. But this approach is insecure.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
回答2:
For any one still searching for this:
add strictSSL: false
to the options object works for me
来源:https://stackoverflow.com/questions/46341322/how-to-ignore-self-signed-certificate-issue-in-request-promise