由于代理和tls握手,go install失败

sz81bmfz  于 2023-10-14  发布在  Go
关注(0)|答案(1)|浏览(140)

命令

  1. go install -v golang.org/x/tools/cmd/godoc@latest

失败并显示消息
proxyconnect tcp:tls:第一条记录看起来不像TLS握手
我假设原因是我在一个公司代理后面,该代理不使用https从我的客户端(我的windows机器)到代理服务器的通信。
proxyno_proxy的windows用户环境变量C:\>reg query HKEY_CURRENT_USER\Environment的设置如下

  1. C:\>reg query HKEY_CURRENT_USER\Environment | findstr /R .PROXY.
  2. HTTP_PROXY=http://myuser:[email protected]:port
  3. HTTPS_PROXY=https://myuser:[email protected]:port
  4. # i also tried http
  5. # HTTPS_PROXY=http://myuser <-- no https
  6. NO_PROXY=localhost,127.0.0.1,.mycomp.com,.foo.mycomp,localhost:5001

HTTPS_PROXY的值从https://myuser...更改为http://myuser...没有区别。用于http的git config git config -l具有以下设置

  1. C:\>git config -l | findstr /R http.
  2. http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
  3. http.sslbackend=openssl
  4. http.proxy=http://myuser:[email protected]:port
  5. http.sslverify=false
  6. https.proxy=http://myuser:[email protected]:port

更新

this answer中,customDialContext用于避免相同的错误消息proxyconnect tcp: tls: first record does not look like a TLS handshake,但用于不同的任务(调用rest服务)。

  1. // Custom dialing function to handle connections
  2. func customDialContext(ctx context.Context, network, addr string) (net.Conn, error) {
  3. conn, err := net.Dial(network, addr)
  4. return conn, err
  5. }

提问

我要怎么做

  • 所以我可以使用go install
  • 并避免或忽略错误proxyconnect tcp: tls: first record does not look like a TLS handshake
  • 自定义拨号功能可以用于安装命令吗(参见上面的更新)?
nnt7mjpx

nnt7mjpx1#

在企业环境中,我建议使用genotrance/px

  • 你可以用--pac=file option或者.ini pac指令启动它。
  • 默认运行在127.0.0.1:3128上

这意味着您的HTTPS_PROXY将变为http://127.0.0.1:3128(不再是myuser:mypass!)
您的设置:

  1. HTTP_PROXY=http://127.0.0.1:3128
  2. HTTPS_PROXY=http://127.0.0.1:3128

注意:HTTPS_PROXY通过HTTP引用相同的代理,* 而不是 * HTTPS。
px.ini中,只放server = http://my.corporate.proxy(同样,仅限HTTP)。
启动它一次(每个Windows会话),然后从CLI或Go程序尝试Internet连接。

相关问题