【问题标题】:how can I get system proxy setting in node js如何在节点 js 中获取系统代理设置
【发布时间】:2017-03-14 17:27:23
【问题描述】:

我正在使用电子在 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?

【问题讨论】:

  • 您可以尝试使用尊重系统代理设置的Electron net API
  • 嗨,@zzm 你找到解决方案了吗?我有同样的问题:'(
  • @MarwenLandoulsi 我听从了 Jastin 的建议,改用 Electron net API
  • 我是os-proxy 的作者,它完全符合您的要求。虽然它还不支持 Windows,但希望得到一些帮助。

标签: node.js proxy electron


【解决方案1】:

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

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

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

【讨论】:

  • 我误解了这条评论是指 http 模块。但是实验表明 electron 没有在 http 模块上设置代理 :(.
【解决方案2】:

你可以使用来自 NPM 的 get-proxy-settings 包。

详情请参考READMEthis answer

【讨论】:

    猜你喜欢
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多