通過設置
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
來取消對HTTPS的證書驗證,以處理x509: certificate signed by unknown authority
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
resp, err := client.Get("https://localhost:8081")
if err != nil {
fmt.Println("error:", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
通過設置TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
來取消對HTTPS的證書驗證,以處理如下錯誤信息:
error: Get https://localhost:8081: x509: certificate signed by unknown authority