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

时间:2021-02-21 23:31:20   收藏:0   阅读:533

使用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
    });
}

原文:https://www.cnblogs.com/freeatalk/p/14425839.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!