通过设置TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 来取消对HTTPS的证书验证,以处理x509: certificate signed by unknown authority
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
// 忽略 https 证书验证
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: transport}
response, err := client.Post(
"https://ch3nnn.cn",
"application/json",
strings.NewReader(jsonString),
)
if err != nil {
common.Logger.Error(err)
return
}
if response.StatusCode == http.StatusOK {
// 调用json包的解析,解析请求body
readAll, _ := ioutil.ReadAll(response.Body)
sonic.Unmarshal(readAll, handler.Strategy)
common.Logger.Debug("success ....")
} else {
common.Logger.Error("Fail ....")
}
}