Browse Source

bugfix: 修复预热任务鉴权参数传递失败问题

kuanglingwei 1 year ago
parent
commit
559d7a1ed7
1 changed files with 14 additions and 3 deletions
  1. 14 3
      curlServer/CurlServer.go

+ 14 - 3
curlServer/CurlServer.go

@@ -9,6 +9,7 @@ import (
 	"net"
 	"net/http"
 	"runtime"
+	"strings"
 	"time"
 )
 
@@ -48,7 +49,7 @@ func (s *CurlServer) CurlWithResolveParam(ctx context.Context, requestCurlObject
 				logger.Println("addr = ", addr)
 				conn, err := dialer.DialContext(ctx, network, addr)
 				if err != nil {
-					logger.Error(err.Error())
+					logger.Error("TCP连接异常: " + err.Error())
 					return nil, err
 				}
 				return conn, nil
@@ -64,10 +65,20 @@ func (s *CurlServer) CurlWithResolveParam(ctx context.Context, requestCurlObject
 		Transport: transport,
 	}
 
+	// 创建一个GET请求, 将转义字符重新转换
+	originalUrl := strings.Replace(requestCurlObject.GetUrl(), "%5B", "[", -1)
+	originalUrl = strings.Replace(originalUrl, "%5D", "]", -1)
+	originalUrl = strings.Replace(originalUrl, "%20", " ", -1)
+	originalUrl = strings.Replace(originalUrl, "%7B", "{", -1)
+	originalUrl = strings.Replace(originalUrl, "%7D", "}", -1)
+	originalUrl = strings.Replace(originalUrl, "%22", "\"", -1)
+	originalUrl = strings.Replace(originalUrl, "%26", "&", -1)
+	logger.Println(originalUrl)
+
 	// 发起 HTTP 请求
-	resp, err := client.Get(requestCurlObject.GetUrl())
+	resp, err := client.Get(originalUrl)
 	if err != nil {
-		logger.Error(err.Error())
+		logger.Error("发送HTTP请求出错, e:" + err.Error() + ", url: " + requestCurlObject.GetUrl())
 		return nil, err
 	}
 	defer resp.Body.Close()