把Post 改为默认Form 需要不默认则调用参数TypeContentEmpty

This commit is contained in:
huangsimin 2018-10-25 19:02:55 +08:00
parent 8a0a21fc5e
commit 166fe96265
2 changed files with 13 additions and 2 deletions

11
base.go
View File

@ -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,8 +32,18 @@ func buildBodyRequest(ver, rawurl string, body *Body) *http.Request {
}
if 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 != "" {
req.Header.Set(HeaderKeyContentType, contentType)

View File

@ -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