]> 127.0.0.1 Git - part/.git/commitdiff
61
authorqydysky <qydysky@foxmail.com>
Tue, 15 Sep 2020 06:04:27 +0000 (14:04 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 15 Sep 2020 06:04:27 +0000 (14:04 +0800)
Reqf.go
Sys.go

diff --git a/Reqf.go b/Reqf.go
index 3417ef36be4fa845b1afad9cc5b83bf054462aa6..5b8144f033b9067b48bdec032b59226792076fc2 100644 (file)
--- 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 1266125bb6e9e9b1c6fd88dec45c4202d1bc7284..8d48e377c30a1fe928f24c8218af42d55d1228ad 100644 (file)
--- 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 {