Axios 错误:无法获取本地颁发者证书

问题描述 投票:0回答:1

我在使用 Axios 提交请求时遇到错误。

    let getConfig = {
        headers: {'PTToken': 'token'},
        params: {
            'filter-id': `${id}`
        }
      }
      try {
        const { data, status } = await axios.get('https://api.practitest.com/api/v2/projects/id/tests.json', getConfig);
        console.log('data', data, status)
      } catch (error) {
        console.log('error', error)
      }

我读过建议将此作为解决方案的帖子:

    let getConfig = {
        headers: {'PTToken': 'token'},
        params: {
            'filter-id': `${id}`
        },
        httpsAgent : {
          rejectUnauthorized: false
        }
      }
      try {
        const { data, status } = await axios.get('https://api.practitest.com/api/v2/id/tests.json', getConfig);
        console.log('data', data, status)
      } catch (error) {
        console.log('error', error)
      }

这不起作用,因为我认为我的设置不正确。
有谁知道如何配置 Axios 请求以在发送 post 和 get 请求时忽略这些 ssl 错误?

typescript api axios
1个回答
0
投票

我尝试重现您的示例并收到以下错误:

The "options.agent" property must be one of Agent-like Object, undefined, or false. Received an instance of Object

这些更改有助于消除错误:

const https = require('https');
...
httpsAgent: new https.Agent({ rejectUnauthorized: true }),
© www.soinside.com 2019 - 2024. All rights reserved.