Skip to content

Instantly share code, notes, and snippets.

@codemodify
Last active January 17, 2019 11:34
Show Gist options
  • Save codemodify/f9211636019e34365fccbdd8e30c8b82 to your computer and use it in GitHub Desktop.
Save codemodify/f9211636019e34365fccbdd8e30c8b82 to your computer and use it in GitHub Desktop.
qosmicparticles-io-samples.go
package main
import (
"fmt"
"bytes"
"io/ioutil"
"net/http"
)
func main() {
payload := `{
"version": "2.0",
"key": "rcd1JN+CkZo2+KKR802bXTujubMbiZARQcyTR8Ku8haqdyaz8pA8Z1kbrWJO2J2CiwFdnr",
"gobSize": 96
}`
data := doPOSTWithJSON("qosmicparticles.io:4444/FetchGobs", payload)
fmt.Println(string(data))
}
func doPOSTWithJSON(endpointURL string, payload []byte) ([]byte, error) {
request, err := http.NewRequest(
"POST",
endpointURL,
bytes.NewBuffer(payload),
)
request.Header.Set("Content-Type", "application/json")
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return nil, err
}
defer response.Body.Close()
data, err := ioutil.ReadAll(response.Body)
return data, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment