1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package project
- import (
- "encoding/json"
- "io/ioutil"
- "log"
- "net/http"
- "strings"
- "testing"
- )
- var (
- apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectList"
- // apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectListDetail"
- )
- func Test_Project(t *testing.T) {
- getData()
- }
- func getData() {
- data := post(apiurl, map[string]string{
- "projectname": "河南大学",
- "s_winner": "洛阳丹尼斯量贩有限公司",
- "jgtime": "1545235200_1599014733",
- })
- log.Println(data)
- }
- //获取项目详情测试用例
- // func Test_ProjectDetails(t *testing.T) {
- // data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
- // "id": "5f6b4e12499cb0822d39c68f",
- // })
- // res := map[string]interface{}{}
- // s, _ := json.Marshal(data)
- // json.Unmarshal(s, &res)
- // log.Println("数据:", res)
- // }
- func post(url string, form map[string]string) (data map[string]interface{}) {
- str := ""
- for k, v := range form {
- str += "&" + k + "=" + v
- }
- log.Println(str)
- res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
- if err != nil {
- log.Println("post err:", err.Error())
- } else if res.Body != nil {
- defer res.Body.Close()
- bs, _ := ioutil.ReadAll(res.Body)
- json.Unmarshal(bs, &data)
- }
- return
- }
|