chore: RequestGet 还是 使用 url.Values
This commit is contained in:
parent
27715b7b27
commit
0d4b189d3b
@ -14,6 +14,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// vals := url.Values{}
|
// vals := url.Values{}
|
||||||
@ -48,12 +49,8 @@ func RequestPostJson(url string, data map[string]any) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 比较完整的 get 实现
|
// 比较完整的 get 实现
|
||||||
func RequestGet(url string, data map[string]any, headers map[string]string) ([]byte, error) {
|
func RequestGet(uri string, vals url.Values, headers map[string]string) ([]byte, error) {
|
||||||
bd, err := json.Marshal(data)
|
req, err := http.NewRequest("GET", uri, strings.NewReader(vals.Encode()))
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
req, err := http.NewRequest("GET", url, bytes.NewBuffer(bd))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user