使用Golang发送带有证书的HTTP请求。

huangapple go评论86阅读模式
英文:

golang: Send http request with certificate

问题

首先,我是新手在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

谢谢任何帮助!

英文:

For first I am newbie in golang.

I try to send https request. I create http.Client like this:

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,
	},
}
}

But as result I get local error: no renegotiation.

Thanks for any help!

答案1

得分: 2

这可能是你正在访问的远程服务器的问题,但这是一个已知的问题(例如,Microsoft Azure服务中存在此问题)。

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

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

英文:

This is likely a problem with the remote server you're accessing, but it is a known problem (with Microsoft Azure services for one).

There may be a workaround on the way for go1.4, but until then the go client still doesn't support TLS renegotiation.

Relevant issue: https://code.google.com/p/go/issues/detail?id=5742

答案2

得分: 1

看起来重新协商(和客户端证书认证)以前是不支持的。这个问题似乎已经通过提交 https://github.com/golang/go/commit/af125a5193c75dd59307fcf1b26d885010ce8bfd 得到修复。

英文:

It looks as though renegotiation (and client certificate authentication) was previously unsupported. This looks to have been fixed by commit https://github.com/golang/go/commit/af125a5193c75dd59307fcf1b26d885010ce8bfd

huangapple
  • 本文由 发表于 2014年7月1日 02:12:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/24496344.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定