PHP
·
发表于 5年以前
·
阅读量:8283
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