csession
Csession provides a client session for http client. It has the same methods as http.Client, but it will automatically save cookies, headers and set referer. This project has part codes from github.com/chzyer/go-fetcher.
Installing csession
go get github.com/coscms/webx/lib/httpsession/csession
Quick Start
1.Before use please New or NewSession
import (
"github.com/coscms/webx/lib/httpsession/csession"
)
session := csession.New()
or
import (
"github.com/coscms/webx/lib/httpsession/csession"
)
session := csession.NewSession(transport, checkRedirect, jar)
NewSession's params are the same as http.Client's fields
2.If you want to customize your headers, your can set HeadersFunc as your func. Default, session.HeadersFunc = session.DefaultHeadersFunc.
session.HeadersFunc = func(req *http.Request) {
session.DefaultHeadersFunc(req)
req.Header.Set("Cache-Control", "max-age=0")
}
3.use session like use client
resp, err := session.Get("http://www.google.com")
forms := url.Values{
"username": {"username"}, "password": {"password"},
}
resp, err := session.PostForm("http://www.google.com", forms)
resp, err := session.Post("http://www.google.com")
resp, err := session.Head(...)
resp, err := sesion.Do(req)
Documents
Please visit GoWalker
LICENSE
BSD License
http://creativecommons.org/licenses/BSD/