mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
fix http client.
This commit is contained in:
parent
06d6c852f5
commit
800bf525ed
@ -8,6 +8,15 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var client = &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
ForceAttemptHTTP2: true,
|
||||||
|
MaxConnsPerHost: 0,
|
||||||
|
MaxIdleConns: 0,
|
||||||
|
MaxIdleConnsPerHost: 999,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// HttpGetBytes 带 cookie 的 GET 请求
|
// HttpGetBytes 带 cookie 的 GET 请求
|
||||||
func HttpGetBytes(url, cookie string) ([]byte, error) {
|
func HttpGetBytes(url, cookie string) ([]byte, error) {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
@ -19,7 +28,7 @@ func HttpGetBytes(url, cookie string) ([]byte, error) {
|
|||||||
if cookie != "" {
|
if cookie != "" {
|
||||||
req.Header["Cookie"] = []string{cookie}
|
req.Header["Cookie"] = []string{cookie}
|
||||||
}
|
}
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -45,7 +54,7 @@ func HttpPostBytes(url string, data []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
req.Header["User-Agent"] = []string{"QQ/8.2.0.1296 CFNetwork/1126"}
|
req.Header["User-Agent"] = []string{"QQ/8.2.0.1296 CFNetwork/1126"}
|
||||||
req.Header["Net-Type"] = []string{"Wifi"}
|
req.Header["Net-Type"] = []string{"Wifi"}
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -78,7 +87,7 @@ func HttpPostBytesWithCookie(url string, data []byte, cookie string, contentType
|
|||||||
if cookie != "" {
|
if cookie != "" {
|
||||||
req.Header["Cookie"] = []string{cookie}
|
req.Header["Cookie"] = []string{cookie}
|
||||||
}
|
}
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user