How to ignore self signed certificate issue in request-promise

*爱你&永不变心* 提交于 2020-07-09 05:42:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!