diff --git a/workflow.go b/workflow.go index cf9c58d..089109b 100644 --- a/workflow.go +++ b/workflow.go @@ -194,17 +194,8 @@ func (wf *Workflow) SetBodyParams(params ...interface{}) *Workflow { return wf } -// Execute 执行 -func (wf *Workflow) Execute() (*Response, error) { - - req := buildBodyRequest(wf.Method, wf.GetStringURL(), wf.Body) - - if wf.Cookies != nil { - for _, c := range wf.Cookies { - req.AddCookie(c) - } - } - +// setHeaderRequest 设置request的头 +func setHeaderRequest(req *http.Request, wf *Workflow) { set := make(map[string]map[string]int) for key, values := range wf.session.Header { for _, v := range values { @@ -233,6 +224,25 @@ func (wf *Workflow) Execute() (*Response, error) { } } +} + +// setHeaderRequest 设置request的临时Cookie, 永久需要在session上设置cookie +func setTempCookieRequest(req *http.Request, wf *Workflow) { + if wf.Cookies != nil { + for _, c := range wf.Cookies { + req.AddCookie(c) + } + } +} + +// Execute 执行 +func (wf *Workflow) Execute() (*Response, error) { + + req := buildBodyRequest(wf.Method, wf.GetStringURL(), wf.Body) + + setHeaderRequest(req, wf) + setTempCookieRequest(req, wf) + resp, err := wf.session.client.Do(req) if err != nil { return nil, err