You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
645 B

4 years ago
package wechat
import (
"io"
"net/http"
"strings"
)
const (
post = "POST"
get = "GET"
)
var client = &http.Client{}
// @Title 请求
func request(method, url, data string, headers ...map[string]string) ([]byte, error) {
reqest, err := http.NewRequest(method, url, strings.NewReader(data))
if err != nil {
return nil, err
}
if len(headers) > 0 {
for key, value := range headers[0] {
reqest.Header.Add(key, value)
}
}
response, err := client.Do(reqest)
if err != nil {
return nil, err
}
defer response.Body.Close()
result, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
return result, nil
}