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