June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// load key pair
|
||||
cert, err := tls.LoadX509KeyPair(
|
||||
"./client.local.tld/client.local.tld.crt",
|
||||
"./client.local.tld/client.local.tld.key",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Error while loading x509 key pair", err)
|
||||
}
|
||||
|
||||
// Create TLS Config in order to had client certificate
|
||||
tlsConfig := &tls.Config{Certificates: []tls.Certificate{cert}}
|
||||
|
||||
tlsConfig.BuildNameToCertificate()
|
||||
transport := &http.Transport{TLSClientConfig: tlsConfig}
|
||||
|
||||
// create http client with our custom transport with TLS config
|
||||
client := &http.Client{Transport: transport}
|
||||
|
||||
res, err := client.Get("https://www.example.com/")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
contents, err := ioutil.ReadAll(res.Body)
|
||||
log.Print(string(contents))
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue