原因:
访问了没有证书的域名或ip地址
解决方法
func NewHttpClient() *http.Client {
t := http.DefaultTransport.(*http.Transport).Clone()
//不对证书进行校验
t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
t.MaxConnsPerHost = 200
t.MaxIdleConnsPerHost = 200
client := &http.Client{
Timeout: 60 * time.Second,
Transport: t,
}
return client
}
client初始化时加上t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
文章讲述了如何在Go语言中创建一个HTTP客户端,配置TLSClientConfig以跳过证书验证,允许访问未认证的域名或IP地址。通过设置InsecureSkipVerify为true,可以忽略证书校验,但这也可能带来安全风险。

被折叠的 条评论
为什么被折叠?



