Documentation ¶
Index ¶
- type HttpRequest
- func (h *HttpRequest) AddCookie(cookie *http.Cookie) *HttpRequest
- func (h *HttpRequest) AddParam(key, value string) *HttpRequest
- func (h *HttpRequest) GetResponse() (*http.Response, error)
- func (h *HttpRequest) PostFile(formname, filename string) *HttpRequest
- func (h *HttpRequest) SetBasicAuth(username string, password string) *HttpRequest
- func (h *HttpRequest) SetBody(data interface{}) *HttpRequest
- func (h *HttpRequest) SetEnableCookie(enable bool) *HttpRequest
- func (h *HttpRequest) SetHeader(key, value string) *HttpRequest
- func (h *HttpRequest) SetHost(host string) *HttpRequest
- func (h *HttpRequest) SetJsonBody(obj interface{}) (*HttpRequest, error)
- func (h *HttpRequest) SetParam(key, value string) *HttpRequest
- func (h *HttpRequest) SetParams(params map[string]interface{}) *HttpRequest
- func (h *HttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpRequest
- func (h *HttpRequest) SetRetries(times int) *HttpRequest
- func (h *HttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpRequest
- func (h *HttpRequest) SetUserAgent(useragent string) *HttpRequest
- func (h *HttpRequest) SetXmlBody(obj interface{}) (*HttpRequest, error)
- func (h *HttpRequest) Settings(settings HttpSettings) *HttpRequest
- func (h *HttpRequest) ToBytes() ([]byte, error)
- func (h *HttpRequest) ToFile(filename string) error
- func (h *HttpRequest) ToJSON(v interface{}) error
- func (h *HttpRequest) ToString() (string, error)
- func (h *HttpRequest) ToXML(v interface{}) error
- type HttpSettings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HttpRequest ¶
type HttpRequest struct {
// contains filtered or unexported fields
}
func NewRequest ¶
func NewRequest(rawUrl, method string) *HttpRequest
func (*HttpRequest) AddCookie ¶
func (h *HttpRequest) AddCookie(cookie *http.Cookie) *HttpRequest
添加请求Cookie
func (*HttpRequest) AddParam ¶
func (h *HttpRequest) AddParam(key, value string) *HttpRequest
增加请求参数
func (*HttpRequest) GetResponse ¶ added in v0.1.6
func (h *HttpRequest) GetResponse() (*http.Response, error)
获取http.response
func (*HttpRequest) PostFile ¶
func (h *HttpRequest) PostFile(formname, filename string) *HttpRequest
PostFile add a post file to the request
func (*HttpRequest) SetBasicAuth ¶
func (h *HttpRequest) SetBasicAuth(username string, password string) *HttpRequest
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*HttpRequest) SetBody ¶
func (h *HttpRequest) SetBody(data interface{}) *HttpRequest
设置请求Body it supports string and []byte.
func (*HttpRequest) SetEnableCookie ¶
func (h *HttpRequest) SetEnableCookie(enable bool) *HttpRequest
SetEnableCookie sets enable/disable cookiejar
func (*HttpRequest) SetHeader ¶
func (h *HttpRequest) SetHeader(key, value string) *HttpRequest
设置请求Header
func (*HttpRequest) SetJsonBody ¶
func (h *HttpRequest) SetJsonBody(obj interface{}) (*HttpRequest, error)
设置Json格式请求Body
func (*HttpRequest) SetParam ¶
func (h *HttpRequest) SetParam(key, value string) *HttpRequest
设置请求参数
func (*HttpRequest) SetParams ¶
func (h *HttpRequest) SetParams(params map[string]interface{}) *HttpRequest
设置键值对格式请求参数
func (*HttpRequest) SetProxy ¶
func (h *HttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpRequest
设置Http代理
func (*HttpRequest) SetRetries ¶
func (h *HttpRequest) SetRetries(times int) *HttpRequest
设置请求失败重试次数 0:不重试(默认) -1:一直重试
func (*HttpRequest) SetTimeout ¶
func (h *HttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpRequest
设置超时时间
func (*HttpRequest) SetUserAgent ¶
func (h *HttpRequest) SetUserAgent(useragent string) *HttpRequest
设置User-Agent
func (*HttpRequest) SetXmlBody ¶
func (h *HttpRequest) SetXmlBody(obj interface{}) (*HttpRequest, error)
设置XML格式请求Body
func (*HttpRequest) Settings ¶
func (h *HttpRequest) Settings(settings HttpSettings) *HttpRequest
设置请求配置
func (*HttpRequest) ToBytes ¶
func (h *HttpRequest) ToBytes() ([]byte, error)
func (*HttpRequest) ToFile ¶
func (h *HttpRequest) ToFile(filename string) error
ToFile saves the body data in response to one file. it calls Response inner.
func (*HttpRequest) ToXML ¶
func (h *HttpRequest) ToXML(v interface{}) error
ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.
type HttpSettings ¶
type HttpSettings struct { ShowDebug bool UserAgent string ConnectTimeout time.Duration ReadWriteTimeout time.Duration // TLSClientConfig *tls.Config Proxy func(*http.Request) (*url.URL, error) CheckRedirect func(req *http.Request, via []*http.Request) error EnableCookie bool Gzip bool DumpBody bool Retries int // if set to -1 means will retry forever }
http.Client settings
Click to show internal directories.
Click to hide internal directories.