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