-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
52 lines (46 loc) · 1.08 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
package http
import (
"crypto/tls"
"io/ioutil"
"net/http"
"strings"
)
func SendUnsecureHTTPSRequest(ip string, method string, body string, headers map[string]string) (int, string, error) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
var req *http.Request
var err error
if !strings.Contains(ip, "https") {
ip = "https://" + ip
}
method = strings.ToUpper(method)
if method == "DELETE" {
req, err = http.NewRequest(method, ip, nil)
} else {
req, err = http.NewRequest(method, ip, strings.NewReader(body))
}
if err == nil {
if headers != nil {
for k, v := range headers {
req.Header.Add(k, v)
}
}
response, err := client.Do(req)
if err == nil {
defer response.Body.Close()
if response.StatusCode == 200 {
bodyBytes, err2 := ioutil.ReadAll(response.Body)
bodyString := string(bodyBytes)
if err2 == nil {
return response.StatusCode, string(bodyString), nil
}
return response.StatusCode, "", err2
}
} else {
return 0, "", err
}
}
return 0, "", nil
}