Skip to content

Commit 25436c0

Browse files
authored
新增http请求参数url encode,防止特殊字符后端处理报错 (#786)
1 parent 707bd57 commit 25436c0

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

common/http_agent/delete.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ package http_agent
1818

1919
import (
2020
"net/http"
21+
"net/url"
2122
"strings"
2223
"time"
2324
)
2425

2526
func delete(client *http.Client, path string, header http.Header, timeoutMs uint64, params map[string]string) (response *http.Response, err error) {
26-
if !strings.HasSuffix(path, "?") {
27-
path = path + "?"
28-
}
29-
for key, value := range params {
30-
path = path + key + "=" + value + "&"
31-
}
32-
if strings.HasSuffix(path, "&") {
33-
path = path[:len(path)-1]
27+
if len(params) > 0 {
28+
if !strings.HasSuffix(path, "?") {
29+
path = path + "?"
30+
}
31+
for key, value := range params {
32+
path = path + key + "=" + url.QueryEscape(value) + "&"
33+
}
34+
if strings.HasSuffix(path, "&") {
35+
path = path[:len(path)-1]
36+
}
3437
}
3538
client.Timeout = time.Millisecond * time.Duration(timeoutMs)
3639
request, errNew := http.NewRequest(http.MethodDelete, path, nil)

common/http_agent/get.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package http_agent
1818

1919
import (
2020
"net/http"
21+
"net/url"
2122
"strings"
2223
"time"
2324
)
@@ -31,7 +32,7 @@ func get(client *http.Client, path string, header http.Header, timeoutMs uint64,
3132
if !strings.HasSuffix(path, "&") {
3233
path = path + "&"
3334
}
34-
path = path + key + "=" + value + "&"
35+
path = path + key + "=" + url.QueryEscape(value) + "&"
3536
}
3637
if strings.HasSuffix(path, "&") {
3738
path = path[:len(path)-1]

0 commit comments

Comments
 (0)