javascript - axios响应错误: certificate has expired

标签 javascript node.js post axios response

我正在使用 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
  });

这行得通。

关于javascript - axios响应错误: certificate has expired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58724317/

相关文章:

javascript - 如何制作饼图聚合数据源?

javascript - 停止触发器函数在Jquery中运行多次

php - 服务器到客户端的更新,无需来自客户端 Websocket 编程的持续/持久请求

javascript - Firebase 托管 + 云功能

javascript - 如何在ajax url中传递多个数组值

c# - 通过 HttpClient.PostAsync 的 POST 请求,主体内有 StorageFile (WinRT)

javascript - 下载文件并将其保存在浏览器的本地存储中

javascript - 在 JS 中创建网格艺术

node.js - 与 postgres 数据库的连接失败

ios - 如何在 iOS 中使用 SLRequest 发布带有私有(private)推文的图片?