1
This commit is contained in:
parent
f715cffbce
commit
dd6cf60934
28
httpcli.go
28
httpcli.go
@ -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) {
|
func HttpPost(url string, params map[string]string, contentType string, body string) (string, error) {
|
||||||
if !StrContains(url, "?") {
|
if !StrContains(url, "?") {
|
||||||
url = url + "?"
|
url = url + "?"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user