base_mini_lib.go 751 B

1234567891011121314151617181920212223242526272829303132333435
  1. package dwmini
  2. import (
  3. "eta/eta_chart_lib/utils"
  4. "fmt"
  5. "io"
  6. "net/http"
  7. "strings"
  8. )
  9. func HttpPost(url, postData, token string) ([]byte, error) {
  10. body := io.NopCloser(strings.NewReader(postData))
  11. client := &http.Client{}
  12. req, err := http.NewRequest("POST", url, body)
  13. if err != nil {
  14. return nil, err
  15. }
  16. req.Header.Add("Authorization", token)
  17. req.Header.Set("Content-Type", "application/json")
  18. resp, err := client.Do(req)
  19. if err != nil {
  20. return nil, err
  21. }
  22. defer resp.Body.Close()
  23. b, err := io.ReadAll(resp.Body)
  24. fmt.Println("HttpPost:" + string(b))
  25. if utils.RunMode == "debug" {
  26. return b, err
  27. }
  28. str := string(b)
  29. str = strings.Trim(str, `"`)
  30. b = utils.DesBase64Decrypt([]byte(str), utils.ETA_MINI_DES_KEY)
  31. return b, err
  32. }