-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.go
71 lines (55 loc) · 1.22 KB
/
request.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package th_tools
import (
"crypto/tls"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
type Request struct{}
/**
* Do a request to Requestor
*
* @params form
* form := url.Values{}
* form.Add("url", "http://google.nl")
**/
func (r Request) Do(method string, uri string, form url.Values) (int, []byte, error) {
mTLSConfig := &tls.Config{
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
},
}
mTLSConfig.PreferServerCipherSuites = true
mTLSConfig.MinVersion = tls.VersionTLS10
mTLSConfig.MaxVersion = tls.VersionTLS10
tr := &http.Transport{
TLSClientConfig: mTLSConfig,
}
hc := &http.Client{Transport: tr}
//log.Println(uri)
//log.Println(form.Encode())
var (
req *http.Request
err error
)
if form != nil {
req, err = http.NewRequest(method, uri, strings.NewReader(form.Encode()))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
} else {
req, err = http.NewRequest(method, uri, nil)
}
if err != nil {
return 0, nil, err
}
response, err := hc.Do(req)
defer response.Body.Close()
if err != nil {
return 0, nil, err
}
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return 0, nil, err
}
return response.StatusCode, contents, nil
}