forked from ltt1987/alidayu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.go
44 lines (38 loc) · 891 Bytes
/
post.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
package alidayu
import (
"io/ioutil"
"net/http"
"strings"
)
var UseHTTP = false
func DoPost(m map[string]string) (success bool, response string) {
if AppKey == "" || AppSecret == "" {
return false, "AppKey or AppSecret is requierd!"
}
body, size := getRequestBody(m)
client := &http.Client{}
var req *http.Request
var err error
if !UseHTTP {
req, err = http.NewRequest("POST", URL_HTTPS, body)
} else {
req, err = http.NewRequest("POST", URL_HTTP, body)
}
if err != nil {
return false, err.Error()
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.ContentLength = size
resp, err := client.Do(req)
if err != nil {
response = err.Error()
return
}
defer resp.Body.Close()
data, _ := ioutil.ReadAll(resp.Body)
response = string(data)
if strings.Contains(response, "success") {
return true, response
}
return false, response
}