无法通过SSL连接

时间:2019-05-31 04:37:37

标签: node.js ssl

我正在尝试与具有1种SSL方式的外部api服务器连接。

我正在Linux中使用nodejs。

我有以下问题:

  1. 如何声明使用我的ssl证书?
  2. 我还在代码中声明ca: fs.readFileSync(process.env.SMS_CERT_PATH),吗?
  3. 我将证书放在哪里?

GlobUtil.prototype.sendSms = (number, msg, callback) => {

    let options = {
        url: format(process.env.APPSMS, number),
        ca: fs.readFileSync(process.env.SMS_CERT_PATH),
        body: msg
    };

    request.post(options, function(error, response, body) {

        if (error) {
            log.error("Error calling sendSms: " + options.url);
            log.error("===== Error =====");
            log.error(error);

            return callback(error);
        }

        if (response.statusCode === 200) {

            return callback(null, true);
        } else {
            result = JSON.parse(body)
            return callback(new Error(result));
        }
    });
}

0 个答案:

没有答案