Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增http请求参数url encode,防止特殊字符后端处理报错 #786

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading