Documentation ¶
Index ¶
- Variables
- func DumpRequest(req *http.Request) ([]byte, error)
- func DumpRequestIndent(req *http.Request) string
- func SetLogFunc(f func(string, ...interface{}))
- func Wget(url, name string) (int, error)
- type Request
- func (req *Request) MergeIn(r *Request)
- func (req *Request) Request() (*http.Request, error)
- func (req *Request) SetAuth(user, pass string) *Request
- func (req *Request) SetBody(body interface{}) error
- func (req *Request) SetCookie(k, v string) *Request
- func (req *Request) SetCookies(kv map[string]string) *Request
- func (req *Request) SetForm(k, v string) *Request
- func (req *Request) SetHeader(k, v string) *Request
- func (req *Request) SetHeaders(kv map[string]string) *Request
- func (req *Request) SetMethod(method string) *Request
- func (req *Request) SetParam(k string, v interface{}) *Request
- func (req *Request) SetParams(query map[string]interface{}) *Request
- func (req *Request) SetRetry(retry int) *Request
- func (req *Request) SetURL(url string) *Request
- type Response
- func Delete(url string, body interface{}) (resp *Response, err error)
- func Get(url string) (*Response, error)
- func Head(url string) (resp *Response, err error)
- func PUT(url string, body interface{}) (resp *Response, err error)
- func Post(url, contentType string, body interface{}) (*Response, error)
- func PostForm(url string, data url.Values) (resp *Response, err error)
- func WarpResponse(resp *http.Response) *Response
- func (resp *Response) Copy() *Response
- func (resp *Response) Download(name string) (int, error)
- func (resp *Response) Dump() ([]byte, error)
- func (resp *Response) DumpIndent() string
- func (resp *Response) JSON(v interface{}) error
- func (resp *Response) StdLib() *http.Response
- func (resp *Response) Text() (string, error)
- type Session
- func (sess *Session) DebugTrace(request *Request)
- func (sess *Session) Delete(url, contentType string, body io.Reader) (resp *Response, err error)
- func (sess *Session) DeleteWithContext(ctx context.Context, url, contentType string, body io.Reader) (resp *Response, err error)
- func (sess *Session) Do(method, url, contentType string, body io.Reader) (*Response, error)
- func (sess *Session) DoRequest(request *Request, ctx ...context.Context) (*Response, error)
- func (sess *Session) DoWithContext(ctx context.Context, method, url, contentType string, body io.Reader) (*Response, error)
- func (sess *Session) Get(url string) (*Response, error)
- func (sess *Session) GetWithContext(ctx context.Context, url string) (*Response, error)
- func (sess *Session) Post(url, contentType string, body io.Reader) (resp *Response, err error)
- func (sess *Session) PostForm(url string, data url.Values) (resp *Response, err error)
- func (sess *Session) PostFormWithContext(ctx context.Context, url string, data url.Values) (resp *Response, err error)
- func (sess *Session) PostWithContext(ctx context.Context, url, contentType string, body io.Reader) (resp *Response, err error)
- func (sess *Session) Put(url, contentType string, body io.Reader) (resp *Response, err error)
- func (sess *Session) PutWithContext(ctx context.Context, url, contentType string, body io.Reader) (resp *Response, err error)
- func (sess *Session) SetAuth(user, pass string) *Session
- func (sess *Session) SetCookie(k, v string) *Session
- func (sess *Session) SetHeader(k, v string) *Session
- func (sess *Session) SetHeaders(kv map[string]string) *Session
- func (sess *Session) SetKeepAlives(keepAlives bool) *Session
- func (sess *Session) SetLogFunc(f func(string, ...interface{})) *Session
- func (sess *Session) SetParam(k string, v interface{}) *Session
- func (sess *Session) SetParams(kv map[string]interface{}) *Session
- func (sess *Session) SetProxy(addr string) error
- func (sess *Session) SetRetry(retry int, retryFunc ...func(Response, error) error) *Session
- func (sess *Session) SetTimeout(timeout int) *Session
Constants ¶
This section is empty.
Variables ¶
var (
ErrEmptyProxy = errors.New("proxy is empty")
)
var
Functions ¶
func DumpRequest ¶
DumpRequest returns the given request in its HTTP/1.x wire representation.
func DumpRequestIndent ¶
DumpRequestIndent warp Dump
Types ¶
type Request ¶
type Request struct { Method string URL string Params map[string]interface{} Headers map[string]string Cookies map[string]string Body []byte Form url.Values Retry int }
Request request
func NewRequest ¶
NewRequest new request
func (*Request) SetCookies ¶
SetCookies cookie
func (*Request) SetHeaders ¶
SetHeaders headers
type Response ¶
Response wrap std response
type Session ¶
type Session struct { *http.Transport *http.Client LogFunc func(string, ...interface{}) // contains filtered or unexported fields }
Session httpclient session Clients and Transports are safe for concurrent use by multiple goroutines for efficiency should only be created once and re-used. so, session is also safe for concurrent use by multiple goroutines.
func (*Session) DebugTrace ¶
DebugTrace trace a request
sess := requests.New() req, err := requests.NewRequest("GET", "http://www.baidu.com", nil) if err != nil { sess.LogFunc("%v", err) } sess.DebugTrace(req)
* Connect: www.baidu.com:80 * Resolved Host: www.baidu.com * Resolved DNS: [14.215.177.39 14.215.177.38], Coalesced: false, err=<nil> * Trying tcp 14.215.177.39:80... * Completed connection: tcp 14.215.177.39:80, err=<nil> * Got Conn: {0xc0000ac020 false false 0s} > GET / HTTP/1.1 > Host: www.baidu.com > User-Agent: Go-http-client/1.1 > Accept-Encoding: gzip > > < HTTP/1.1 200 OK < Transfer-Encoding: chunked < Bdpagetype: 1 < Bdqid: 0x85d6ecb5000fcc70 ...more...
func (*Session) DeleteWithContext ¶
func (sess *Session) DeleteWithContext(ctx context.Context, url, contentType string, body io.Reader) (resp *Response, err error)
DeleteWithContext send delete request
func (*Session) DoWithContext ¶
func (sess *Session) DoWithContext(ctx context.Context, method, url, contentType string, body io.Reader) (*Response, error)
DoWithContext http request
func (*Session) GetWithContext ¶
GetWithContext http request
func (*Session) PostFormWithContext ¶
func (sess *Session) PostFormWithContext(ctx context.Context, url string, data url.Values) (resp *Response, err error)
PostFormWithContext post form request
func (*Session) PostWithContext ¶
func (sess *Session) PostWithContext(ctx context.Context, url, contentType string, body io.Reader) (resp *Response, err error)
PostWithContext send post request
func (*Session) PutWithContext ¶
func (sess *Session) PutWithContext(ctx context.Context, url, contentType string, body io.Reader) (resp *Response, err error)
PutWithContext send put request
func (*Session) SetHeaders ¶
SetHeaders headers
func (*Session) SetKeepAlives ¶
SetKeepAlives set transport disableKeepAlives default transport is keepalive, if set false, only use the connection to the server for a single HTTP request.
func (*Session) SetLogFunc ¶
SetLogFunc set log handler
func (*Session) SetProxy ¶
SetProxy set proxy addr os.Setenv("HTTP_PROXY", "http://127.0.0.1:9743") os.Setenv("HTTPS_PROXY", "https://127.0.0.1:9743")
func (*Session) SetTimeout ¶
SetTimeout set client timeout