electron http/https 使用 https-proxy-agent 请求设置代理

使用https-proxy-agent

  npm i https-proxy-agent

在代码中使用

需要加上rejectUnauthorized: false,否则可能会出现错误unable to verify the first certificate

if(url.startsWith("https")){
    req= https.request(url,{
      method: "POST",
      rejectUnauthorized: false,
      headers: headers ,
      agent: agent
    });
}else {
    req= http.request(url, {
       method: "POST",
       headers: headers,
       agent: agent
    });
}
posted @ 2021-02-21 15:11  闲一话  阅读(4184)  评论(0编辑  收藏  举报