Last active
January 17, 2019 11:34
-
-
Save codemodify/f9211636019e34365fccbdd8e30c8b82 to your computer and use it in GitHub Desktop.
qosmicparticles-io-samples.go
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
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