执行https请求时出现CERT_UNTRUSTED错误

aru*_*boj 5 https node.js node-request

我试图https request从我的节点服务器端执行,但它给我以下错误: -

Caught exception: Error: CERT_UNTRUSTED
Run Code Online (Sandbox Code Playgroud)

如果我执行http request然后它工作正常但https 链接 不起作用.

这是我的代码: -

var request = require('request');
request('https://en.m.wikipedia.org/wiki/Astrid_Olofsdotter_of_Sweden', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Show the HTML for the Google homepage.
  }
})
Run Code Online (Sandbox Code Playgroud)

任何的想法?

abi*_*lng 0

它看起来像是 SSL 问题,修复网络环境 SSL 的最佳方法。


现在,您可以通过将rejectUnauthorized设置为来绕过问题false

const request = require("request");
const https = require('https');
const agentOptions = {
    host: 'en.m.wikipedia.org',
    port: '443',
    path: '/wiki/Astrid_Olofsdotter_of_Sweden',
    rejectUnauthorized: false
};
const agent = new https.Agent(agentOptions);

const postOption = {
    method: 'GET',
    agent: agent,
    uri: 'https://en.m.wikipedia.org/wiki/Astrid_Olofsdotter_of_Sweden'
};

request(postOption, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
});
Run Code Online (Sandbox Code Playgroud)