diff --git a/base.go b/base.go index df2d88a..e8c6f07 100644 --- a/base.go +++ b/base.go @@ -10,10 +10,12 @@ import ( func buildBodyRequest(ver, rawurl string, body *Body) *http.Request { var req *http.Request var err error + contentType := "" if body.IOBody == nil { req, err = http.NewRequest(ver, rawurl, nil) } else { + contentType = TypeURLENCODED var bodybuf *bytes.Buffer switch body.IOBody.(type) { case []byte: @@ -30,10 +32,12 @@ func buildBodyRequest(ver, rawurl string, body *Body) *http.Request { panic(err) } - if body.ContentType == "" { - req.Header.Set(HeaderKeyContentType, TypeURLENCODED) - } else { - req.Header.Set(HeaderKeyContentType, body.ContentType) + if body.ContentType != "" { + contentType = body.ContentType + } + + if contentType != "" { + req.Header.Set(HeaderKeyContentType, contentType) } return req diff --git a/session.go b/session.go index 513d435..aaedacf 100644 --- a/session.go +++ b/session.go @@ -48,6 +48,8 @@ const ( TypeXML = "text/xml" // TypeURLENCODED 类型 TypeURLENCODED = "application/x-www-form-urlencoded" + // TypeForm PostForm类型 + TypeForm = TypeURLENCODED // TypeFormData 类型 TypeFormData = "multipart/form-data" // HeaderKeyHost Host diff --git a/workflow.go b/workflow.go index ca7522b..202fa51 100644 --- a/workflow.go +++ b/workflow.go @@ -1,6 +1,7 @@ package requests import ( + "log" "net/http" "net/url" "regexp" @@ -231,6 +232,7 @@ func mergeMapList(headers ...map[string][]string) map[string][]string { // setHeaderRequest 设置request的头 func setHeaderRequest(req *http.Request, wf *Workflow) { req.Header = mergeMapList(req.Header, wf.session.Header, wf.Header) + log.Println(wf.Header, wf.session.Header) } // setHeaderRequest 设置request的临时Cookie, 永久需要在session上设置cookie