commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package httpsx
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 获取HTTPS证书过期时间
|
||||
|
||||
func main() {
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
client := &http.Client{Transport: tr}
|
||||
|
||||
seedUrl := "https://www.baidu.cn"
|
||||
resp, err := client.Get(seedUrl)
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err != nil {
|
||||
fmt.Errorf(seedUrl, " 请求失败")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//fmt.Println(resp.TLS.PeerCertificates[0])
|
||||
certInfo := resp.TLS.PeerCertificates[0]
|
||||
fmt.Println("过期时间:", certInfo.NotAfter)
|
||||
fmt.Println("组织信息:", certInfo.Subject)
|
||||
}
|
||||
Reference in New Issue
Block a user