From bc71af3b591e18fb1aee23eaba8e1eda54b3d1ed Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Fri, 12 May 2017 02:13:21 +1000 Subject: [PATCH] general post json --- upload.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/upload.go b/upload.go index 95f2ade..bd0d3d1 100644 --- a/upload.go +++ b/upload.go @@ -52,3 +52,19 @@ func postFileForm(filename string, targetURL string, formFieldName string) (strJ fmt.Println(string(strJSON)) return strJSON, nil } + +func postJSON(jsonB []byte, targetURL string) (resp string, err error) { + req, err := http.NewRequest("POST", targetURL, bytes.NewBuffer(jsonB)) + if err != nil { + return + } + client := &http.Client{} + r, err := client.Do(req) + if err != nil { + return + } + defer r.Body.Close() + b, _ := ioutil.ReadAll(r.Body) + resp = string(b) + return +}