Skip to content

Instantly share code, notes, and snippets.

@d1str0
Created September 18, 2013 17:39
Show Gist options
  • Save d1str0/6612701 to your computer and use it in GitHub Desktop.
Save d1str0/6612701 to your computer and use it in GitHub Desktop.
client := &http.Client{}
posturl := server + "deliver_message" // Attempt to hit the deliver_message api call,
values := url.Values{"value1": {someValue}, "value2": {"some constant string"}} // with this info.
data, err := json.Marshal(values) // Turn values into json.
// check err.
req, err := http.NewRequest("POST", posturl, strings.NewReader(string(data))) // Turn json []bytes into a string then ioReader.
// check err.
req.Header.Add("Content-Type", "application/json") // Set the apropriate header.
resp, err := client.Do(req)
// check err.
defer resp.Body.Close() // Defer closing of the request until it is read into an ioutil.
body, err := ioutil.ReadAll(resp.Body)
// check err.
fmt.Println(string(body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment