From: qydysky Date: Tue, 15 Sep 2020 06:04:27 +0000 (+0800) Subject: 61 X-Git-Tag: v0.0.2~15 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=df3e1d5414512fef0c0a0dd78555ebac34564c5c;p=part%2F.git 61 --- diff --git a/Reqf.go b/Reqf.go index 3417ef3..5b8144f 100644 --- a/Reqf.go +++ b/Reqf.go @@ -5,6 +5,7 @@ import ( "io" "os" "time" + "strings" "net/http" "errors" "io/ioutil" @@ -14,10 +15,12 @@ import ( type Rval struct { Url string + PostStr string Timeout int Referer string Cookie string Proxy string + ContentType string Accept string AcceptLanguage string Connection string @@ -71,10 +74,12 @@ func (this *req) Reqf_1(val Rval) (error) { var ( Url string = val.Url + PostStr string = val.PostStr Referer string = val.Referer Cookie string = val.Cookie Proxy string = val.Proxy Accept string = val.Accept + ContentType string = val.ContentType Connection string = val.Connection AcceptLanguage string = val.AcceptLanguage Timeout int = val.Timeout @@ -98,13 +103,24 @@ func (this *req) Reqf_1(val Rval) (error) { } if Url==""{return errors.New("Url is \"\"")} - req,_ := http.NewRequest("GET", Url, nil) + + Method := "GET" + var body io.Reader + if len(PostStr) > 0 { + Method = "POST"; + body = strings.NewReader(PostStr); + if Connection == "" {Connection = "Keep-Alive"} + if ContentType == "" {ContentType = "application/x-www-form-urlencoded"} + } + + req,_ := http.NewRequest(Method, Url, body) if Cookie!=""{req.Header.Add("Cookie",Cookie)} if Referer!=""{req.Header.Add("Referer",Referer)} if Connection!=""{req.Header.Set("Connection",Connection)} if AcceptLanguage!=""{req.Header.Set("Accept-Language",AcceptLanguage)} - if Referer!=""{req.Header.Add("Accept",Accept)} + if Accept!=""{req.Header.Add("Accept",Accept)} + if ContentType!=""{req.Header.Set("Content-Type", ContentType)} //添加请求头 req.Header.Add("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36") resp, err := client.Do(req) diff --git a/Sys.go b/Sys.go index 1266125..8d48e37 100644 --- a/Sys.go +++ b/Sys.go @@ -78,6 +78,13 @@ func (this *sys) GetTime() string { return now[len(now)-4:] } +func (this *sys) GetMTime() int64 { + return time.Now().UnixNano() / int64(time.Millisecond) +} +func (this *sys) GetSTime() int64 { + return time.Now().Unix() +} + func (this *sys) GetFreePort() int { addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0") if err != nil {