chore: request data 的值可以是任意格式
This commit is contained in:
parent
9d11619e48
commit
27715b7b27
@ -14,7 +14,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// vals := url.Values{}
|
||||
@ -49,8 +48,12 @@ func RequestPostJson(url string, data map[string]any) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 比较完整的 get 实现
|
||||
func RequestGet(url string, vals url.Values, headers map[string]string) ([]byte, error) {
|
||||
req, err := http.NewRequest("GET", url, strings.NewReader(vals.Encode()))
|
||||
func RequestGet(url string, data map[string]any, headers map[string]string) ([]byte, error) {
|
||||
bd, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req, err := http.NewRequest("GET", url, bytes.NewBuffer(bd))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -70,8 +73,12 @@ func RequestGet(url string, vals url.Values, headers map[string]string) ([]byte,
|
||||
}
|
||||
|
||||
// 默认是 json 请求
|
||||
func RequestPost(url string, vals url.Values, headers map[string]string) ([]byte, error) {
|
||||
req, err := http.NewRequest("POST", url, strings.NewReader(vals.Encode()))
|
||||
func RequestPost(url string, data map[string]any, headers map[string]string) ([]byte, error) {
|
||||
bd, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(bd))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user