project_test.go 853 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package project
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "log"
  6. "net/http"
  7. "strings"
  8. "testing"
  9. )
  10. var (
  11. apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectList"
  12. )
  13. func Test_Project(t *testing.T) {
  14. getData()
  15. }
  16. func getData() {
  17. data := post(apiurl, map[string]string{
  18. "name": "河南大学",
  19. "winner": "洛阳丹尼斯量贩有限公司",
  20. "time": "1545235200_1599014733",
  21. })
  22. log.Println(data)
  23. }
  24. func post(url string, form map[string]string) (data map[string]interface{}) {
  25. str := ""
  26. for k, v := range form {
  27. str += "&" + k + "=" + v
  28. }
  29. log.Println(str)
  30. res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
  31. if err != nil {
  32. log.Println("post err:", err.Error())
  33. } else if res.Body != nil {
  34. defer res.Body.Close()
  35. bs, _ := ioutil.ReadAll(res.Body)
  36. json.Unmarshal(bs, &data)
  37. }
  38. return
  39. }