add httppostcontent
This commit is contained in:
parent
a7c34b44d7
commit
c832144308
15
httpcli.go
15
httpcli.go
@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func HttpGet(url string, params *XObject) (string, error) {
|
||||
@ -14,6 +15,7 @@ func HttpGet(url string, params *XObject) (string, error) {
|
||||
if resp.StatusCode != 200 {
|
||||
return "", errors.New("HttpGet error Status:" + resp.Status)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||
return string(bytes), nil
|
||||
} else {
|
||||
@ -35,3 +37,16 @@ func HttpGetAsJson(url string, params *XObject) (*XObject, string, error) {
|
||||
}
|
||||
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