diff --git a/httpcli.go b/httpcli.go index 919823d..ed0bdaa 100644 --- a/httpcli.go +++ b/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 + } +}