title: Golang HTTPS/TLS POST client/server
body: <p>I have written a simple client/server in Go that will do an HTTP GET over TLS, but I'm trying to also make it capable of doing an HTTP POST over TLS.</p>
  
  <p>In the example below <code>index.html</code> just contains the text <code>hello</code>, and the HTTP GET is working fine. I want the client to get the HTTP GET and write back, <code>hello world</code> to the server.</p>
  
  <p>client</p>
  
  <pre><code>package main
  
  import (
      "crypto/tls"
      "fmt"
      "io/ioutil"
      "net/http"
      "strings"
  )
  
  func main() {
      link := "https://10.0.0.1/static/index.html"
  
      tr := &amp;http.Transport{
          TLSClientConfig: &amp;tls.Config{InsecureSkipVerify: true},
      }
      client := &amp;http.Client{Transport: tr}
      response, err := client.Get(link)
      if err != nil {
          fmt.Println(err)
      }
      defer response.Body.Close()
  
      content, _ := ioutil.ReadAll(response.Body)
      s := strings.TrimSpace(string(content))
  
      fmt.Println(s)
  
      // out := s + " world"      
      // Not working POST...
      // resp, err := client.Post(link, "text/plain", &amp;out)
  
  }
  </code></pre>
  
  <p>server</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "log"
      "net/http"
  )
  
  func main() {
      http.HandleFunc("/static/", func (w http.ResponseWriter, r *http.Request) {
          fmt.Println("Got connection!")
          http.ServeFile(w, r, r.URL.Path[1:])
      })
      log.Fatal(http.ListenAndServeTLS(":443", "server.crt", "server.key", nil))
  }
  </code></pre>
  
  <p>I also currently have nothing to handle the POST on the server side, but I just want it to print it out to the screen so when I run the client I will see the server print <code>hello world</code>.</p>
  
  <p>How should I fix my client code to do a proper POST? And what should the corresponding server code look like to accept the POST? Any help would be appreciated, I'm having trouble finding HTTPS/TLS POST examples.</p>