From a2cf25638011fff60e3825b1f4f489b9b7fb98ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 14 Jul 2022 11:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B0=86=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=86=99=E5=85=A5=E4=B8=8A=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request/form.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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 ||