util.go 851 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package payermax
  2. import (
  3. "io"
  4. "net/http"
  5. "strings"
  6. "bet24.com/log"
  7. )
  8. const dateFormat = "2006-01-02T15:04:05.000Z07:00"
  9. // http post json 请求
  10. func httpPostByJson(url string, data string, sign string) string {
  11. req, err := http.NewRequest("POST", url, strings.NewReader(data))
  12. if err != nil {
  13. log.Error("HttpPostByJson NewRequest error %v", err)
  14. return ""
  15. }
  16. req.Header.Add("Content-Type", "application/json")
  17. req.Header.Add("Cache-Control", "no-cache")
  18. req.Header.Set("sign", sign)
  19. resp, err := (&http.Client{}).Do(req)
  20. if err != nil {
  21. log.Error("HttpPostByJson Request Do error %v", err)
  22. return ""
  23. }
  24. defer resp.Body.Close()
  25. body, err := io.ReadAll(resp.Body)
  26. if err != nil {
  27. log.Error("HttpPostByJson Response error %v", err)
  28. return ""
  29. }
  30. // log.Debug("HttpPost Send:%v", string(body))
  31. return string(body)
  32. }