在 Electron 应用程序中发出 HTTPS 请求时,为什么会收到“错误:写入 EPROTO”?

Zac*_*sch 11 https node.js electron

几天来我一直在为这个问题苦苦挣扎,所以我向 Stackoverflow 的聪明人寻求帮助。这是交易:

系统详情

  • 节点版本(由于 Electron 依赖关系而无法更改):v4.1.1
  • 电子版本:v0.34.3
  • 操作系统版本:Mac OSX Yosemite 10.10.5 (14F1021)

问题描述

我正在构建一个必须与我公司的应用程序服务器进行通信的Electron应用程序。服务器连接必须通过 HTTPS。我正在使用 Node 的内置https模块。当向服务器发出请求时,我收到以下错误:

{ [Error: write EPROTO] code: 'EPROTO', errno: 'EPROTO', syscall: 'write', address: undefined }

我对此进行了大量的谷歌搜索,我发现的大多数内容都指向代理,但我没有使用代理。我尝试过以下方法:

  • rejectUnauthorized: false在选项哈希中设置
  • 修改secureProtocol选项(无结果)
  • 尝试设置--tls-cipher-list(不知道我在那里做什么)

curl我可以毫无问题地提出请求。不幸的是,我无法发布我所请求的实际 URL。

示例代码

以下是一些说明该问题的示例代码(Coffeescript):

https = require 'https'

options = {
  host: '[Application URL]'
  path: '/'
  method: 'GET'
  port: 443
}

options.agent = new https.Agent(options)

callback = (response) ->
  str = ''
  console.log response
  console.log "STATUS: #{response.statusCode}"
  console.log "HEADERS: #{JSON.stringify(response.headers)}"
  response.setEncoding 'utf-8'
  response.on 'data', (chunk) -> str += chunk
  response.on 'end', -> console.log str

makeRequest = ->
  req = https.request options, callback
  req.on 'error', (err) ->
    console.log err
  req.end()

makeRequest()
Run Code Online (Sandbox Code Playgroud)

有谁知道可能导致此问题的原因是什么?是Node的问题还是应用服务器的配置问题?这个错误正在杀死我并阻止我在工作中达到里程碑,所以任何帮助将不胜感激。谢谢!

小智 -7

要解决此问题,您需要设置 https-proxy,可以使用以下命令来完成:

npm config set https-proxy http://proxy.example.com:8080
Run Code Online (Sandbox Code Playgroud)