This commit is contained in:
白茶清欢 2024-07-23 21:40:53 +08:00
parent 8f533f5b04
commit a1418c290c

View File

@ -10,6 +10,7 @@ package request
import ( import (
"bytes" "bytes"
"errors" "errors"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
@ -36,10 +37,10 @@ type form struct {
// //
// Date : 00:34 2022/7/3 // Date : 00:34 2022/7/3
func (f *form) Parse(ctx *gin.Context, receiver interface{}) error { func (f *form) Parse(ctx *gin.Context, receiver interface{}) error {
handleConfig := define.GetHttpHandleConfig()
requestBody, _ := ioutil.ReadAll(ctx.Request.Body) requestBody, _ := io.ReadAll(ctx.Request.Body)
// 请求信息写入上下文 // 请求信息写入上下文
ctx.Set(define.RecordRequestDataField, string(requestBody)) ctx.Set(handleConfig.RecordRequestDataField, string(requestBody))
// 因为请求体被读一遍之后就没了,重新赋值 requestBody // 因为请求体被读一遍之后就没了,重新赋值 requestBody
ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(requestBody)) ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(requestBody))
method := strings.ToUpper(ctx.Request.Method) method := strings.ToUpper(ctx.Request.Method)