1
This commit is contained in:
parent
06880e9f72
commit
9048589a4d
32
httpcli.go
32
httpcli.go
@ -5,7 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
net_url "net/url"
|
net_url "net/url"
|
||||||
//"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -64,31 +64,25 @@ func HttpGetEx(url string, params map[string]string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
func HttpPost(url string, params map[string]string, contentType string, body string) (string, error) {
|
||||||
func HttpGetAsJson(url string, params map[string]string) (map, string, error) {
|
if !StrContains(url, "?") {
|
||||||
respStr, err := HttpGet(url, params)
|
url = url + "?"
|
||||||
if err != nil {
|
|
||||||
return nil, respStr, err
|
|
||||||
}
|
}
|
||||||
respObj := NewXoFromJsonStr(respStr)
|
{
|
||||||
if !respObj.IsObject() {
|
u := net_url.Values{}
|
||||||
return nil, respStr, errors.New("HttpGetAsJson error invalid json format")
|
for key, val := range params {
|
||||||
|
u.Set(key, val)
|
||||||
|
}
|
||||||
|
url = url + u.Encode()
|
||||||
}
|
}
|
||||||
return respObj, respStr, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func HttpPostContent(url string, contentType string, body string, response *string) (error) {
|
|
||||||
*response = ""
|
|
||||||
resp, err := http.Post(url, contentType, strings.NewReader(body))
|
resp, err := http.Post(url, contentType, strings.NewReader(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||||
*response = string(bytes)
|
return string(bytes), nil
|
||||||
return nil
|
|
||||||
} else {
|
} else {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user