-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_utils.go
43 lines (39 loc) · 866 Bytes
/
http_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dss
import (
"crypto/tls"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"time"
)
// HTTPGet HTTP Get
func HTTPGet(url, userAgent string, prams map[string]string, timeOut time.Duration) ([]byte, error) {
//Skip certificate verification
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
//http cookie
cookieJar, _ := cookiejar.New(nil)
client := &http.Client{
Timeout: timeOut * time.Second,
Jar: cookieJar,
Transport: tr,
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
for k, v := range prams {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
req.Header.Add("User-Agent", userAgent)
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
return body, err
}