diff --git a/base.go b/base.go index cfe3e5d..ea243e9 100644 --- a/base.go +++ b/base.go @@ -19,10 +19,12 @@ func buildBodyRequest(wf *Workflow) *http.Request { switch wf.Body.GetIOBody().(type) { case []byte: bodybuf = bytes.NewBuffer(wf.Body.GetIOBody().([]byte)) + case string: + bodybuf = bytes.NewBuffer([]byte(wf.Body.GetIOBody().(string))) case *bytes.Buffer: bodybuf = bytes.NewBuffer(wf.Body.GetIOBody().(*bytes.Buffer).Bytes()) default: - panic(errors.New("the type is not exist, type is" + reflect.TypeOf(wf.Body.GetIOBody()).String())) + panic(errors.New("the type is not exist, type is " + reflect.TypeOf(wf.Body.GetIOBody()).String())) } req, err = http.NewRequest(wf.Method, wf.GetRawURL(), bodybuf) } diff --git a/session.go b/session.go index 93126d6..a33c978 100644 --- a/session.go +++ b/session.go @@ -307,6 +307,13 @@ func (ses *Session) ClearCookies() { ses.client.Jar = ses.cookiejar } +// Head 请求 +func (ses *Session) Head(url string) *Workflow { + wf := NewWorkflow(ses, url) + wf.Method = "HEAD" + return wf +} + // Get 请求 func (ses *Session) Get(url string) *Workflow { wf := NewWorkflow(ses, url) @@ -335,20 +342,6 @@ func (ses *Session) Patch(url string) *Workflow { return wf } -// Delete 请求 -func (ses *Session) Delete(url string) *Workflow { - wf := NewWorkflow(ses, url) - wf.Method = "DELETE" - return wf -} - -// Head 请求 -func (ses *Session) Head(url string) *Workflow { - wf := NewWorkflow(ses, url) - wf.Method = "HEAD" - return wf -} - // Options 请求 func (ses *Session) Options(url string) *Workflow { wf := NewWorkflow(ses, url) @@ -356,6 +349,13 @@ func (ses *Session) Options(url string) *Workflow { return wf } +// Delete 请求 +func (ses *Session) Delete(url string) *Workflow { + wf := NewWorkflow(ses, url) + wf.Method = "DELETE" + return wf +} + // CloseIdleConnections closes the idle connections that a session client may make use of // 从levigross/grequests 借鉴 func (ses *Session) CloseIdleConnections() {