From 0ec26e57212e5647dffbcac81b2019d2aecc953d Mon Sep 17 00:00:00 2001 From: jjxu <428192774@qq.com> Date: Thu, 16 Nov 2023 14:11:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8=E4=B8=BA=E7=89=B9?= =?UTF-8?q?=E5=AE=9A=E7=B1=BB=E5=9E=8B=E7=9A=84body=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=B6=EF=BC=8C=E6=B2=A1=E6=9C=89=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=B7=BB=E5=8A=A0Content-Type=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- body.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/body.go b/body.go index 64e873b..3b282ff 100644 --- a/body.go +++ b/body.go @@ -7,7 +7,9 @@ package simpleRequest -import "mime/multipart" +import ( + "mime/multipart" +) // EntryMark 请求体条目标记,用于标记输入的body内容格式 type EntryMark string @@ -60,10 +62,16 @@ func (s *BodyConf) SetModel(model any) *BodyConf { func (s *BodyConf) SetFromDataFile(key, filePath string) *BodyConf { s.simpleReq.BodyEntryMark = MultipartEntryType s.simpleReq.BodyEntries[FormFilePathKey.string()+key] = filePath + if s.simpleReq.headers.Get(hdrContentTypeKey) == "" { + s.simpleReq.headers.Set(hdrContentTypeKey, formDataType) + } return s } func (s *BodyConf) SetFromDataMultipartFile(key string, multFile *multipart.FileHeader) *BodyConf { s.simpleReq.BodyEntryMark = MultipartEntryType s.simpleReq.BodyEntries[key] = multFile + if s.simpleReq.headers.Get(hdrContentTypeKey) == "" { + s.simpleReq.headers.Set(hdrContentTypeKey, formDataType) + } return s }