Golang忽略HTTPS证书

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的证书验证,以处理x509: certificate signed by unknown authority

你可能感兴趣的:(Go的http/https,golang,https,开发语言)