From dcd280563aabe0cbf831a7af2c7b85e9b552791a Mon Sep 17 00:00:00 2001 From: guzeng Date: Tue, 30 Mar 2021 00:30:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=91=E9=80=81json?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- url.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/url.go b/url.go index 72260a9..2605705 100755 --- a/url.go +++ b/url.go @@ -4,6 +4,7 @@ package network import ( + "bytes" "crypto/md5" "encoding/hex" "errors" @@ -45,6 +46,33 @@ func FnPost(url, param string) ([]byte, error) { return body, nil } +/** + * post 请求 + */ +func PostJson(url string, param []byte) ([]byte, error) { + httpClient := &http.Client{} + + req, err := http.NewRequest("POST", url, bytes.NewBuffer(param)) + if err != nil { + return []byte(""), err + } + + req.Header.Set("Content-Type", "application/json") + + resp, err := httpClient.Do(req) + if err != nil { + return []byte(""), err + } + + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return []byte(""), err + } + + return body, nil +} + /** * 取本地IP */