import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
"strconv"
"time"
// 略去
)
// GetSheet .
func GetSheet(start, end time.Time) ([]byte, error) {
cookieJar, _ := cookiejar.New(nil)
client := &http.Client{
Jar: cookieJar,
}
_, err := client.Get("http://10.10.10.10/login/")
if err != nil {
return nil, err
}
_, err = client.PostForm("http://10.10.10.10/login/", url.Values{
"username": {"aa},
"password": {"bb"},
"logintype": {"user"},
})
if err != nil {
return nil, err
}
sheetQuery := url.Values{
"startDate": {start.Format("2006-01-02")},
"endDate": {end.Format("2006-01-02")},
}
result, err := client.Get("http://10.10.10.10/login/original_records/?" + sheetQuery.Encode())
if err != nil {
return nil, err
}
b, err := ioutil.ReadAll(result.Body)
if err != nil {
return nil, err
}
result.Body.Close()
return b, nil
}
go---get, postForm
最新推荐文章于 2024-05-20 09:40:37 发布