From 25436c0fcfc640a4a0e860c7743f47f8ab397ad3 Mon Sep 17 00:00:00 2001 From: CZJCC Date: Tue, 26 Nov 2024 16:22:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ehttp=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=8F=82=E6=95=B0url=20encode=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6=E5=90=8E=E7=AB=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=8A=A5=E9=94=99=20(#786)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/http_agent/delete.go | 19 +++++++++++-------- common/http_agent/get.go | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/common/http_agent/delete.go b/common/http_agent/delete.go index fe8948d6..bfa73544 100644 --- a/common/http_agent/delete.go +++ b/common/http_agent/delete.go @@ -18,19 +18,22 @@ package http_agent import ( "net/http" + "net/url" "strings" "time" ) func delete(client *http.Client, path string, header http.Header, timeoutMs uint64, params map[string]string) (response *http.Response, err error) { - if !strings.HasSuffix(path, "?") { - path = path + "?" - } - for key, value := range params { - path = path + key + "=" + value + "&" - } - if strings.HasSuffix(path, "&") { - path = path[:len(path)-1] + if len(params) > 0 { + if !strings.HasSuffix(path, "?") { + path = path + "?" + } + for key, value := range params { + path = path + key + "=" + url.QueryEscape(value) + "&" + } + if strings.HasSuffix(path, "&") { + path = path[:len(path)-1] + } } client.Timeout = time.Millisecond * time.Duration(timeoutMs) request, errNew := http.NewRequest(http.MethodDelete, path, nil) diff --git a/common/http_agent/get.go b/common/http_agent/get.go index 6de4d448..62185d4f 100644 --- a/common/http_agent/get.go +++ b/common/http_agent/get.go @@ -18,6 +18,7 @@ package http_agent import ( "net/http" + "net/url" "strings" "time" ) @@ -31,7 +32,7 @@ func get(client *http.Client, path string, header http.Header, timeoutMs uint64, if !strings.HasSuffix(path, "&") { path = path + "&" } - path = path + key + "=" + value + "&" + path = path + key + "=" + url.QueryEscape(value) + "&" } if strings.HasSuffix(path, "&") { path = path[:len(path)-1]