From 8a0a21fc5e9d3aee7679d3a067bdb57ee1bf65d5 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 25 Oct 2018 18:45:46 +0800 Subject: [PATCH] =?UTF-8?q?PostForm=20=E4=B8=8E=20=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F=E7=9A=84=E5=88=86=E8=BE=A8=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.go | 12 ++++++++---- session.go | 2 ++ workflow.go | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) 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