http.go 501 B

123456789101112131415161718192021222324
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "net/http"
  6. )
  7. func postQuery(requestURL string, jsonBytes []byte) (*http.Response, error) {
  8. req, err := http.NewRequest("POST", requestURL, bytes.NewBuffer(jsonBytes))
  9. if err != nil {
  10. return nil, fmt.Errorf("Error creating post request: %s", err)
  11. }
  12. req.Header.Set("Content-Type", "application/json")
  13. client := &http.Client{}
  14. resp, err := client.Do(req)
  15. if err != nil {
  16. return nil, fmt.Errorf("Error posting query: %v", err)
  17. }
  18. return resp, nil
  19. }