一、問題背景
基於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')