"sync"
"io"
"os"
+ "context"
"time"
"strings"
"net/http"
ResponseCode int
Respon []byte
UsedTime time.Duration
+ Cancel chan struct{}
sync.Mutex
}
return url.Parse(Proxy)
}
client.Transport = &http.Transport{Proxy: proxy}
+ } else {
+ client.Transport = &http.Transport{}
}
if Url==""{return errors.New("Url is \"\"")}
body = strings.NewReader(PostStr);
if ContentType == "" {ContentType = "application/x-www-form-urlencoded"}
}
-
+
+ cx, cancel := context.WithCancel(context.Background())
req,_ := http.NewRequest(Method, Url, body)
+ req = req.WithContext(cx)
+
+ go func(){
+ this.Cancel = make(chan struct{})
+ <- this.Cancel
+ cancel()
+ }()
+
if Accept==""{Accept = `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8`}
if Connection==""{Connection = "keep-alive"}
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)
if err != nil {