From f64dd9f191dff341b4eb430d7bacc44a3db9a279 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期五, 04 三月 2022 10:12:45 +0800 Subject: [PATCH] fix nil --- extend/util/httpUtil.go | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/extend/util/httpUtil.go b/extend/util/httpUtil.go index 0f3f267..621755e 100644 --- a/extend/util/httpUtil.go +++ b/extend/util/httpUtil.go @@ -15,6 +15,7 @@ CONTENT_TYPE_FORM = "application/x-www-form-urlencoded" CONTENT_TYPE_MULFORM = "multipart/form-data" CONTENT_TYPE_JSON = "application/json" + CONTENT_TYPE_UTF8_JSON = "application/json;charset=utf-8" ) func DoPostRequest(url string, contentType string, body map[string]interface{}, params map[string]string, headers map[string]string) ([]byte, error) { @@ -78,4 +79,39 @@ return resultBytes, err } return resultBytes, nil +} + +//鏋勯�燿elete璇锋眰 +func DoDeleteRequest(url string, contentType string, body map[string]interface{}, headers map[string]string) ([]byte, error) { + var resultBytes []byte + var bodyJson []byte + if body != nil { + var err error + bodyJson, err = json.Marshal(body) + if err != nil { + return resultBytes, err + } + } + request, err := http.NewRequest("DELETE", url, bytes.NewBuffer(bodyJson)) + if err != nil { + return resultBytes, err + } + request.Header.Set("Content-type", contentType) + // add headers + if headers != nil { + for key, val := range headers { + request.Header.Add(key, val) + } + } + client := &http.Client{} + resp, err := client.Do(request) + if err != nil { + return resultBytes, err + } + defer resp.Body.Close() + resultBytes, err = ioutil.ReadAll(resp.Body) + if err != nil { + return resultBytes, err + } + return resultBytes, nil } \ No newline at end of file -- Gitblit v1.8.0