This commit is contained in:
aozhiwei 2024-07-10 14:20:26 +08:00
parent f715cffbce
commit dd6cf60934

View File

@ -68,6 +68,34 @@ func HttpGetEx(url string, params map[string]string,
}
}
func HttpGetEx2(url string, params map[string]string) (*http.Response, string, error) {
if !StrContains(url, "?") {
url = url + "?"
}
{
u := net_url.Values{}
for key, val := range params {
u.Set(key, val)
}
url = url + u.Encode()
}
client := &http.Client{}
request, err := http.NewRequest("GET", url, nil)
if err != nil {
panic("http.NewRequest error")
}
if resp, err := client.Do(request); err == nil {
defer resp.Body.Close()
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
return resp, string(bytes), nil
} else {
return resp, "", err
}
} else {
return nil, "", err
}
}
func HttpPost(url string, params map[string]string, contentType string, body string) (string, error) {
if !StrContains(url, "?") {
url = url + "?"