-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.go
More file actions
executable file
·79 lines (62 loc) · 1.73 KB
/
utils.go
File metadata and controls
executable file
·79 lines (62 loc) · 1.73 KB
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
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"io/ioutil"
"net/http"
"crypto/tls"
"strings"
"net/url"
)
func GETS(uri string,PHPSESSID string) string {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
//向服务端发送get请求
request, err := http.NewRequest("GET", uri, nil)
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
request.Header.Set("Cookie", "PHPSESSID=" + PHPSESSID)
response, err := client.Do(request)
if err != nil {
panic(err)
}
if response.StatusCode == 200 {
body, _ := ioutil.ReadAll(response.Body)
response.Body.Close()
return string(body)
}
response.Body.Close()
return GETS(uri,PHPSESSID)
}
func POSTS(uri string, datas map[string]string,PHPSESSID string) string {
postValues := url.Values{}
for key, value := range datas {
postValues.Add(key, value)
}
body := ioutil.NopCloser(strings.NewReader(postValues.Encode())) //把form数据编下码
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
request, err := http.NewRequest("POST", uri, body)
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
request.Header.Set("Cookie", "PHPSESSID=" + PHPSESSID)
resp, err := client.Do(request)
if err != nil {
// handle error
panic(err)
return "{}"
}
if resp.StatusCode != 200 {
fmt.Println("重新开始请求:",uri)
return POSTS(uri,datas,PHPSESSID)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
// handle error
}
fmt.Println("resp. cookies: ",resp.Header)
resp.Body.Close()
return string(data)
}