x509: certificate signed by unknown authority (golang http请求报错)

原因:
访问了没有证书的域名或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,https,golang)