node后台fetch请求数据-Hostname/IP doesn't match certificate's altnames解决方法

   一、问题背景

     基于express框架,node后台fetch请求数据,报错Hostname/IP doesn't match certificate's altnames。。。。。

require('isomorphic-fetch');

fetch(url)

二 、两种方式解决。

  1、设置rejectUnauthorized:false

const https = require("https");

const options = {
  agent: new https.Agent({
    rejectUnauthorized: false
  })
};

fetch(url, options)

  2、当前服务器hosts 文件设置

// hosts文件配置
10.x.x.x  api.weixin.qq.com



// 之前访问的URL为,那么就对应到了10.x.x.x的服务器转发了
fetch('api.weixin.qq.com/getticket/xxxxx')

// 如果10.x.x.x代理服务器有端口号8090,那么fetch地址也要加上端口号8090

fetch('api.weixin.qq.com:8090/getticket/xxxxx')

  

原文地址:https://www.cnblogs.com/ldld/p/10826012.html