【问题标题】:golang: Send http request with certificategolang:发送带有证书的http请求
【发布时间】:2016-05-30 09:37:28
【问题描述】:

首先我是golang的新手。

我尝试发送 https 请求。我这样创建 http.Client:

func httpClient(c *Config) (httpClient *http.Client) {
cert, _ := tls.LoadX509KeyPair(c.CertFile, c.KeyFile)

ssl := &tls.Config{
    Certificates:       []tls.Certificate{cert},
    InsecureSkipVerify: true,
}

ssl.Rand = rand.Reader
return &http.Client{
    Transport: &http.Transport{
        TLSClientConfig: ssl,
    },
}
}

但结果我得到了local error: no renegotiation。

感谢您的帮助!

【问题讨论】:

    标签: https go


    【解决方案1】:

    这可能是您正在访问的远程服务器的问题,但这是一个已知问题(与 Microsoft Azure 服务有关)。

    go1.4 可能会有解决方法,但在那之前,go 客户端仍然不支持 TLS 重新协商。

    相关问题:https://code.google.com/p/go/issues/detail?id=5742

    【讨论】:

    • 我之前看过这个链接,但认为有人知道具体的解决方案。有趣的 go-curl 会帮助我吗?我明天试试。感谢您的回答!
    • go-curl 对我没有帮助。我可以用另一种方式做同样的行为吗?
    • 你可以直接使用 curl 运行你想要的请求吗?这通常是解决问题的好方法。
    • 是的,我尝试通过下一个代码运行所需的请求:curl -X POST --cacert /Users/sergio/.ssh/betfair.crt --data "username=USERNAME&password=PASSWORD" --header "Content-Type: application/x-www-form-urlencoded" --header "X-Application: APPLICATION_KEY" https://identitysso.betfair.com/api/certlogin 或 go-curl gist.github.com/sergio1990/59d8d675e0bf80789bfb,但结果始终相同:{"loginStatus":"CERT_AUTH_REQUIRED"}。据我了解,附加证书有问题。 curl 7.30.0 (x86_64-apple-darwin13.0) libcurl/7.30.0 SecureTransport zlib/1.2.5
    • 嗯...这很有趣:在装有 Ubuntu 14.04 的服务器上一切正常,但在我的本地 Mac OS 10.9 上存在问题。
    【解决方案2】:

    似乎以前不支持重新协商(和客户端证书身份验证)。这看起来已经被提交 https://github.com/golang/go/commit/af125a5193c75dd59307fcf1b26d885010ce8bfd 修复了

    【讨论】:

      猜你喜欢
      • 2018-05-14
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 2023-04-10
      相关资源
      最近更新 更多