package wgetimport ( "crypto/tls" "crypto/x509" "io" "net/http" "os")func clIEnt(rootCa,rootKey string) *http.ClIEnt { var tr *http.Transport certs,err := tls.LoadX509KeyPair(rootCa,rootKey) if err != nil { tr = &http.Transport{ TLSClIEntConfig: &tls.Config{InsecureSkipVerify: true},} } else { ca,err := x509.ParseCertificate(certs.Certificate[0]) if err != nil { return &http.ClIEnt{Transport: tr} } pool := x509.NewCertPool() pool.AddCert(ca) tr = &http.Transport{ TLSClIEntConfig: &tls.Config{RootCAs: pool},} } return &http.ClIEnt{Transport: tr}}func Wget(url,name,rootCa,rootKey string) (bool,error) { resp,err := clIEnt(rootCa,rootKey).Get(url) if err != nil { return false,err } defer resp.Body.Close() file,err := os.Create(name) if err != nil { return false,err } io.copy(file,resp.Body) file.Close() return true,nil}总结
以上是内存溢出为你收集整理的Golang httptls 通信,带证书请求小实例全部内容,希望文章能够帮你解决Golang httptls 通信,带证书请求小实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)