You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
747 B

  1. package util
  2. import (
  3. "code.google.com/p/weed-fs/go/glog"
  4. "io/ioutil"
  5. "net/http"
  6. "net/url"
  7. )
  8. func Post(url string, values url.Values) ([]byte, error) {
  9. r, err := http.PostForm(url, values)
  10. if err != nil {
  11. glog.V(0).Infoln("post to", url, err)
  12. return nil, err
  13. }
  14. defer r.Body.Close()
  15. b, err := ioutil.ReadAll(r.Body)
  16. if err != nil {
  17. glog.V(0).Infoln("read post result from", url, err)
  18. return nil, err
  19. }
  20. return b, nil
  21. }
  22. func Get(url string) ([]byte, error) {
  23. r, err := http.Get(url)
  24. if err != nil {
  25. glog.V(0).Infoln("getting ", url, err)
  26. return nil, err
  27. }
  28. defer r.Body.Close()
  29. b, err := ioutil.ReadAll(r.Body)
  30. if err != nil {
  31. glog.V(0).Infoln("read get result from", url, err)
  32. return nil, err
  33. }
  34. return b, nil
  35. }