通过设置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))
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)