Golang https请求发生错误
`
x509: certificate signed by unknown authority
`
### 重点: 引入"crypto/tls"
````golang
import (
"crypto/tls"
"log"
"net/http"
)
func get(url string, headers map[string]string) *http.Response {
tr := &http.Transport{ //解决x509: certificate signed by unknown authority
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{
Timeout: 15 * time.Second,
Transport: tr, //解决x509: certificate signed by unknown authority
}
req, err := http.NewRequest("GET", url, nil)
for k, v := range headers {
req.Header.Add(k, v)
}
if err != nil {
log.Println(err.Error())
return nil
}
resp, err := client.Do(req)
if err != nil {
log.Println(err.Error())
return nil
}
return resp
}
````
有疑问加站长微信联系(非本文作者))