diff --git a/main.go b/main.go index 58d286b..824311a 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,11 @@ package main import ( + "context" "fmt" "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt" + "io" "strings" "videoplayer/dao" "videoplayer/handler" @@ -36,12 +38,14 @@ func writeLogger(c *gin.Context) { params = c.Request.URL.RawQuery } if method == "POST" { - var data interface{} - err := c.ShouldBind(&data) - if err != nil { - fmt.Println("bind json failed") + params = c.Request.PostForm.Encode() + if params == "" { + // 克隆请求 + req := c.Request.Clone(context.Background()) + // 读取原始请求体内容 + bodyBytes, _ := io.ReadAll(req.Body) + params = string(bodyBytes) } - params = fmt.Sprintf("%v", data) } res := dao.InsertLogToDB(path, ip, method, params) if res == 0 {