Axios response Error: certificate has expired

Axios response Error: certificate has expired

我正在使用 axios 向 diro 发送请求以创建具有端点 /user/create 的用户。

但是,我一直收到这样的错误:

Error response: { Error: certificate has expired
    at TLSSocket.onConnectSecure (_tls_wrap.js:1055:34)
    at TLSSocket.emit (events.js:198:13)
    at TLSSocket.EventEmitter.emit (domain.js:448:20)
    at TLSSocket._finishInit (_tls_wrap.js:633:8)

这是我的要求:

const DIRO_API_KEY = ******
createUserToDiro = ({
  phone,
  first_name,
  last_name,
  birth_date,
  mcc_code
}) => {
  const mobile = phone;
  const firstname = first_name;
  const lastname = last_name;
  const dob = formatDiroDob(birth_date);
  const mcc = mcc_code;
  axios.post('https://api.dirolabs.com/user/create'), {
    firstname,
    lastname,
    dob,
    mobile,
    mcc,
    apikey: DIRO_API_KEY
  })
  .then(rs => console.log('Success response:', rs))
  .catch(err => console.log('Error response:',err));

};

是什么导致了这个问题,有什么办法可以解决吗?

axios库报错明确提到证书已过期

请让 diro 更新 SSL 证书。

我们可以跳过在 Axios npm 库中检查 SSL 的另一种方法如下

const axios = require('axios');
const https = require('https');

// At request level
const agent = new https.Agent({
    rejectUnauthorized: false
});

// Make a request for a user
axios.get('/user/create', { httpsAgent: agent })
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });

这有效。

更简单的方法,使用这个环境变量 NODE_TLS_REJECT_UNAUTHORIZED=0