-
Notifications
You must be signed in to change notification settings - Fork 1
/
WebQQ.http.go
72 lines (67 loc) · 1.66 KB
/
WebQQ.http.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
72
package webqq
import (
"bytes"
"fmt"
"net/http"
"net/url"
"time"
// "github.com/pa001024/reflex/util"
)
// 获取特定cookie值
func (this *WebQQ) getCookie(url *url.URL, name string) (ret string) {
for _, v := range this.client.Jar.Cookies(url) {
if v.Name == name {
return v.Value
}
}
return
}
// 带参数Referer GET
func (this *WebQQ) getWithReferer(urlStr, referer string) (res *http.Response, err error) {
req, err := http.NewRequest("GET", urlStr, nil)
for _, v := range this.client.Jar.Cookies(req.URL) {
req.AddCookie(v)
}
req.Header.Add("Referer", referer)
ch := make(chan bool)
go func() {
res, err = this.client.Do(req)
if res != nil {
this.client.Jar.SetCookies(req.URL, res.Cookies())
}
<-ch
}()
select {
case ch <- true:
case <-time.After(60 * time.Second):
http.DefaultTransport.(*http.Transport).CancelRequest(req)
err = fmt.Errorf("Timeout POST %s", urlStr)
}
close(ch)
return
}
// 带参数Referer POST
func (this *WebQQ) postFormWithReferer(urlStr, referer string, val url.Values) (res *http.Response, err error) {
req, err := http.NewRequest("POST", urlStr, bytes.NewBufferString(val.Encode()))
for _, v := range this.client.Jar.Cookies(req.URL) {
req.AddCookie(v)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Referer", referer)
ch := make(chan bool)
go func() {
res, err = this.client.Do(req)
if res != nil {
this.client.Jar.SetCookies(req.URL, res.Cookies())
}
<-ch
}()
select {
case ch <- true:
case <-time.After(60 * time.Second):
http.DefaultTransport.(*http.Transport).CancelRequest(req)
err = fmt.Errorf("Timeout POST %s", urlStr)
}
close(ch)
return
}