node.js - 如何在 Node js 中获取系统代理设置

标签 node.js proxy electron

我正在使用 Electron 在 Windows 上编写桌面应用程序。现在我需要使用系统全局代理设置作为我自己的代理,同时使用请求来获取这样的数据

    request({
        url: "http://ahdas.drnh.gov.tw/index.php",
        method: "POST",
        proxy: this.proxyRequestUrl,
        headers: {
            "User-Agent": this.mainWindow.webContents.session.getUserAgent(),
            "Accept": "application/json, text/javascript, */*; q=0.01",
            "Accept-Encoding": "gzip, deflate",
            "Cookie": cookies
        },
        form: {'act': 'Display/built/' + bookKey + "/" + postPageKey}
    }, (err, response, body) => {

    });

那么,如何获取系统全局代理设置并将其分配给 this.proxyRequestUrl?

最佳答案

如果您从渲染器进行 http 调用,它将使用系统默认的代理设置。

如果您需要从主进程进行 http 调用,您可以使用 electron-remote remote-ajax-module这将通过渲染器进程进行调用。

您还可以使用 electron-fetch在主进程中,它将使用系统代理设置。

关于node.js - 如何在 Node js 中获取系统代理设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42792669/

相关文章:

node.js - puppeteer page.authenticate https 代理不起作用

node.js - express.js 代理

jquery - 使用 Electron 时无法加载socket.io.js文件

electron - 如何理解 atom-shell 的浏览器端与客户端

electron - webkitSpeechRecognition 抛出错误 "network"

mysql - 使用sequelize从使用自动增量id迁移到uuid

当 Node js 调用时,Python3 不会写入文件

javascript - coupon.getItemTypes() 不是属于ToMany 的函数

node.js - 如何从私有(private) Azure Blob 存储容器中删除 Blob

https - 如何在squid3中配置HTTPS支持