电子应用程序的设置代理

问题描述 投票:6回答:1

我正在使用某些npm模块,这些模块在后台获取请求以从网站中提取一些数据。但是没有选项或设置来为这些请求设置代理,因此我想知道如何为整个电子应用设置代理,以便所有请求都通过该代理?

proxy electron http-proxy
1个回答
0
投票

使用request

使用environment variables

process.env.HTTP_PROXY = 'http://192.168.0.36:3128'

使用Axios

安装此软件包:

npm install https-proxy-agent

然后:

const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent');

let config = {}
config.httpsAgent = new HttpsProxyAgent('http://192.168.0.36:3128')
config.url = 'https://example.com'
config.method = 'GET'

axios(config).then(...).catch(...)

Electron app

对于Wall应用程序(如HTML中的IMG SRC,您可以使用Electron支持的命令行开关:

const { app } = require('electron')
app.commandLine.appendSwitch('proxy-server', '172.17.0.2:3128')
app.on('ready', () => {
  // Your code here
})

请参见documentation

© www.soinside.com 2019 - 2024. All rights reserved.