node.js - ElectronJS Windows Server 代理 PAC URL 连接超时
问题描述
由于先进的安全性和防火墙,我需要通过 Electron 应用程序的 PAC URL 代理从不接受来自外部(TCP 或 HTTP(S))的请求的服务器建立 WebSocket 连接。唯一可接受的解决方案是带有已定义PAC URL 代理的 HTTPS(端口 443)请求。我必须通过系统内的 TCP 读取数据并通过 HTTPS websocket 发送。
我选择将 ElectronJS 与 NodejS 包一起使用,一切正常,我必须连接到外部 WebSocket 服务器。我尝试了以下事情
- 然后我尝试通过在此链接上设置
--proxy-pac-url
找到的方式将集成的 Chrome 浏览器设置为使用代理,这有效,但仅在 Chrome 的命令行中。该应用程序抛出连接超时,因为它似乎没有使用与 Chrome 相同的 WebSocket 设置
const { app, BrowserWindow} = require('electron')
app.commandLine.appendSwitch('proxy-pac-url', 'http://someURL.com:9001/proxy.pac')
var wsUri = "wss://echo.websocket.org/";
var websocket = new WebSocket(wsUri); //works in Chrome, not in the code
- https-proxy-agent的 websocket 示例。它因包含意外对象的错误而失败(不包含逻辑原因)
this.proxyHost = 'http://someURL.com:9001/proxy.pac'
log.info('Is client ' + this.name + ' already connected: ' + this.isConnected)
if (!this.isConnected) {
let wsEndpoint = `ws://${this.host}:${this.port}?auth=${this.auth}`
if (this.port == '443') {
wsEndpoint = `wss://${this.host}:${this.port}?auth=${this.auth}`
}
if (this.proxyHost) {
const options = url.parse(this.proxyHost)
const agent = new HttpsProxyAgent(options)
this.socket = new WebSocket(wsEndpoint, '', { agent: agent })
log.info('Connecting client ' + wsEndpoint + ' via proxy: ' + this.proxyHost)
} else {
this.socket = new WebSocket(wsEndpoint)
log.info('Connecting client ' + wsEndpoint)
}
return true
}
return false
- 作为最后一个选项,我尝试使用此链接
ses.setProxy(config, callback)
上的内置会话功能(请参阅下面的代码)。我没有收到任何错误,但我仍然超时
this.proxyHost = 'http://someURL.com:9001/proxy.pac'
const { app, BrowserWindow} = require('electron')
var wsUri = "wss://echo.websocket.org/";
var win = new BrowserWindow({//some settings})
win.webContents.session.setProxy(this.proxyHost, function (e) {
log.info(e);
log.info('Odlicno')
return true
})
我不明白一切如何通过命令行工作,但无法通过应用程序代码工作。我确定我在应用程序和 Chrome 控制台中使用相同的代码
解决方案
推荐阅读
- c# - 隐藏“.txt”扩展名并从文件夹加载文件名
- php - 如何处理ajax调用的海量请求
- regex - 使用 grok 匹配自定义样式的电子邮件地址
- sockets - HTTP 多部分/表单数据。当二进制数据没有字符串表示时会发生什么?
- linux - 在启动期间仅运行一次 ansible 任务,并在结束时运行一项 ansible 任务
- c# - 如何以 HTML 格式呈现从数据库返回的 SQL Server 文件流 .jpg 图像
- java - 按钮适用于android中的第二次点击
- python - 使用评估生成器的准确度为 0%,但在使用相同数据进行训练期间的准确度为 75%——这是怎么回事?
- arrays - 在 PowerShell 中的数组上使用 Invoke-WebRequest
- python - 尝试检索类属性时出错。