From 166fe96265c6add4337b08be22c5caf1768c85de Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 25 Oct 2018 19:02:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8APost=20=E6=94=B9=E4=B8=BA=E9=BB=98?= =?UTF-8?q?=E8=AE=A4Form=20=E9=9C=80=E8=A6=81=E4=B8=8D=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=88=99=E8=B0=83=E7=94=A8=E5=8F=82=E6=95=B0TypeContentEmpty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.go | 13 +++++++++++-- session.go | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/base.go b/base.go index e8c6f07..d070b35 100644 --- a/base.go +++ b/base.go @@ -15,7 +15,6 @@ func buildBodyRequest(ver, rawurl string, body *Body) *http.Request { if body.IOBody == nil { req, err = http.NewRequest(ver, rawurl, nil) } else { - contentType = TypeURLENCODED var bodybuf *bytes.Buffer switch body.IOBody.(type) { case []byte: @@ -33,7 +32,17 @@ func buildBodyRequest(ver, rawurl string, body *Body) *http.Request { } if body.ContentType != "" { - contentType = body.ContentType + if body.ContentType == TypeContentEmpty { + contentType = "" + } else { + contentType = body.ContentType + } + } else { + if contentType == "" { + if ver == "POST" || ver == "PUT" || ver == "Patch" { + contentType = TypeURLENCODED + } + } } if contentType != "" { diff --git a/session.go b/session.go index aaedacf..b45dc04 100644 --- a/session.go +++ b/session.go @@ -50,6 +50,8 @@ const ( TypeURLENCODED = "application/x-www-form-urlencoded" // TypeForm PostForm类型 TypeForm = TypeURLENCODED + // TypeContentEmpty 没有Form的类型 Content + TypeContentEmpty = "ContentEmpty" // TypeFormData 类型 TypeFormData = "multipart/form-data" // HeaderKeyHost Host