在 node.js 中使用请求承诺将外部 api 数据打印到控制台时出错

Error using request-promise in node.js to print external api data to console

我只是想将一些数据打印到控制台,以确保我的 node.js 应用程序正在接收要处理的数据。我已经像这样格式化了我的代码。

const rP = require('request-promise');

rP({
    'method'  : 'GET',
    'uri'     : 'https://football-data.org/v2/competitions/PL/matches',
    'json'    : true,
    'headers' : {
        'X-Auth-Token' : 'api-key'
    },
    'insecure': true
})
.then(console.log, console.log);

我得到的错误是

RequestError: Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: football-data.org. is not in the cert's altnames: DNS:api.football-data.org

我已经尝试将“ 'insecure' : true ”添加到参数中,但正如另一个答案中所建议的那样没有效果。同样的答案也建议使用 'self-signed certificates' 并指出我 here。我是 node.js 的新手,所以不熟悉从服务器发出 api 调用,也不理解 link 中关于自签名证书的信息。

如有任何建议,我们将不胜感激。

抱歉,如果这个问题格式不正确,这是我的第一个问题。

rejectUnauthorized: false 添加到您传递给请求的对象中。尽管如此,从安全的角度来看这不是一个好主意,