Created
September 18, 2013 17:39
-
-
Save d1str0/6612701 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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