Skip to content

Commit

Permalink
新增http请求参数url encode,防止特殊字符后端处理报错 (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
CZJCC authored Nov 26, 2024
1 parent 707bd57 commit 25436c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
19 changes: 11 additions & 8 deletions common/http_agent/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion common/http_agent/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package http_agent

import (
"net/http"
"net/url"
"strings"
"time"
)
Expand All @@ -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]
Expand Down

0 comments on commit 25436c0

Please sign in to comment.