Skip to content

Instantly share code, notes, and snippets.

@gambrell
Created September 23, 2015 20:56
Show Gist options
  • Save gambrell/4c27620a37665e017b97 to your computer and use it in GitHub Desktop.
Save gambrell/4c27620a37665e017b97 to your computer and use it in GitHub Desktop.
http post json
func postJson(url string, jsonStr []byte) {
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment