From 4eb213aa6dd9d55cbca99d5cbbcc61fe79743a43 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 23 Oct 2018 17:20:17 +0800 Subject: [PATCH] v0.0.6 --- workflow.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) 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