add httppostcontent

This commit is contained in:
aozhiwei 2020-12-16 17:55:55 +08:00
parent a7c34b44d7
commit c832144308

View File

@ -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
}
}