代码改变世界

golang https 调用禁用ssl校验

2021-05-14 17:56  方斌  阅读(750)  评论(0编辑  收藏  举报
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}
    var url = ""
    req, _ := http.NewRequest("GET", url, nil)
    resp, err :=client.Do(req)

    if err != nil {
        fmt.Println("error:", err)
        return
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}