前端之家收集整理的这篇文章主要介绍了
golang https,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
package main
import (
"crypto/tls"
"net/http"
)
func main() {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},}
client := &http.Client{Transport: tr}
url := "https://www.baidu.com"
var err error
var req *http.Request
var resp *http.Response
if req,err = http.NewRequest("GET",url,nil); err != nil {
println(err.Error())
return
}
if resp,err = client.Do(req); err != nil {
println(err.Error())
return
}
defer resp.Body.Close()
switch resp.TLS.Version {
case tls.VersionSSL30:
println("SSLV3")
case tls.VersionTLS10:
println("TLSv1")
case tls.VersionTLS11:
println("TLSv1.1")
case tls.VersionTLS12:
println("TLSv1.2")
}
}