--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
package main
import(
"crypto/rand"
"crypto/tls"
"io/ioutil"
"log"
"net"
"net/http"
"compress/gzip"
"strings"
"time"
)
func main() {
cert, err := tls.LoadX509KeyPair("certificate.pem", "key.pem")
if err != nil {
log.Fatalf("Failed to load X509 key pair: %s", err)
}
ssl: = &tls.Config{
Certificates: []tls.Certificate{cert},
InsecureSkipVerify: true,
}
ssl.Rand = rand.Reader
client: = &http.Client{
Transport: &http.Transport{
Dial: func(network, addr string)(net.Conn, error) {
return net.DialTimeout(network, addr, time.Duration(time.Second*3))
},
TLSClientConfig: ssl,
},
}
requestBody := strings.NewReader("{}");
req, _ := http.NewRequest("POST", "https://www....", requestBody)
// some custom headers
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
response, err := client.Do(req)
if err != nil {
log.Fatalf("Failed to make request: %s", err)
}
if response.StatusCode != 200 {
log.Fatalf("FAILED: Got status: " + response.Status)
}
defer response.Body.Close()
// in case response is gziped, run that through the gzip reader to de decompress
if strings.Contains(response.Header.Get("Content-Encoding"), "gzip") {
response.Body, err = gzip.NewReader(response.Body)
if err != nil {
return
}
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalf("Could not read response body: %s", err)
}
log.Println(string(data))
}
k, this is for posterity in case anyone ever looks for something like this. A very simple example..