add httppostcontent
This commit is contained in:
parent
a7c34b44d7
commit
c832144308
15
httpcli.go
15
httpcli.go
@ -4,6 +4,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HttpGet(url string, params *XObject) (string, error) {
|
func HttpGet(url string, params *XObject) (string, error) {
|
||||||
@ -14,6 +15,7 @@ func HttpGet(url string, params *XObject) (string, error) {
|
|||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return "", errors.New("HttpGet error Status:" + resp.Status)
|
return "", errors.New("HttpGet error Status:" + resp.Status)
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
} else {
|
} else {
|
||||||
@ -35,3 +37,16 @@ func HttpGetAsJson(url string, params *XObject) (*XObject, string, error) {
|
|||||||
}
|
}
|
||||||
return respObj, respStr, err
|
return respObj, respStr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HttpPostContent(url string, contentType string, body string) (string, error) {
|
||||||
|
resp, err := http.Post(url, contentType, strings.NewReader(body))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||||
|
return string(bytes), nil
|
||||||
|
} else {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user