diff --git a/request/form.go b/request/form.go index 0af5690..1aab816 100644 --- a/request/form.go +++ b/request/form.go @@ -8,10 +8,14 @@ package request import ( + "bytes" "errors" + "io/ioutil" "net/http" "strings" + "git.zhangdeman.cn/zhangdeman/gin/define" + "github.com/gin-gonic/gin" ) @@ -29,6 +33,11 @@ type form struct { // // Date : 00:34 2022/7/3 func (f *form) Parse(ctx *gin.Context, receiver interface{}) error { + requestBody, _ := ioutil.ReadAll(ctx.Request.Body) + // 请求信息写入上下文 + ctx.Set(define.RecordRequestDataField, string(requestBody)) + // 因为请求体被读一遍之后就没了,重新赋值 requestBody + ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(requestBody)) method := strings.ToUpper(ctx.Request.Method) if method == http.MethodGet || method == http.MethodPatch ||