Documentation ¶
Index ¶
- type HttpClient
- func (h *HttpClient) AddCookie(cookie *http.Cookie) *HttpClient
- func (h *HttpClient) AddParam(key, value string) *HttpClient
- func (h *HttpClient) GetResponse() (*http.Response, error)
- func (h *HttpClient) PostFile(formname, filename string) *HttpClient
- func (h *HttpClient) SetBasicAuth(username string, password string) *HttpClient
- func (h *HttpClient) SetBody(data any) *HttpClient
- func (h *HttpClient) SetEnableCookie(enable bool) *HttpClient
- func (h *HttpClient) SetHeader(key, value string) *HttpClient
- func (h *HttpClient) SetHost(host string) *HttpClient
- func (h *HttpClient) SetJsonBody(obj any) *HttpClient
- func (h *HttpClient) SetParam(key, value string) *HttpClient
- func (h *HttpClient) SetParams(params map[string]any) *HttpClient
- func (h *HttpClient) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpClient
- func (h *HttpClient) SetRetries(times int) *HttpClient
- func (h *HttpClient) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpClient
- func (h *HttpClient) SetUserAgent(useragent string) *HttpClient
- func (h *HttpClient) SetXmlBody(obj any) *HttpClient
- func (h *HttpClient) Settings(settings HttpSettings) *HttpClient
- func (h *HttpClient) ToBytes() ([]byte, error)
- func (h *HttpClient) ToFile(filename string) error
- func (h *HttpClient) ToJSON(v any) error
- func (h *HttpClient) ToString() (string, error)
- func (h *HttpClient) ToXML(v any) error
- type HttpSettings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HttpClient ¶ added in v0.2.37
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient
func NewClient ¶ added in v0.2.37
func NewClient(rawUrl, method string) *HttpClient
NewClient http客户端
func (*HttpClient) AddCookie ¶ added in v0.2.37
func (h *HttpClient) AddCookie(cookie *http.Cookie) *HttpClient
AddCookie 添加请求Cookie
func (*HttpClient) AddParam ¶ added in v0.2.37
func (h *HttpClient) AddParam(key, value string) *HttpClient
AddParam 增加请求参数
func (*HttpClient) GetResponse ¶ added in v0.2.37
func (h *HttpClient) GetResponse() (*http.Response, error)
GetResponse 获取http.response
func (*HttpClient) PostFile ¶ added in v0.2.37
func (h *HttpClient) PostFile(formname, filename string) *HttpClient
PostFile add a post file to the request
func (*HttpClient) SetBasicAuth ¶ added in v0.2.37
func (h *HttpClient) SetBasicAuth(username string, password string) *HttpClient
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*HttpClient) SetBody ¶ added in v0.2.37
func (h *HttpClient) SetBody(data any) *HttpClient
SetBody 设置请求Body it supports string and []byte.
func (*HttpClient) SetEnableCookie ¶ added in v0.2.37
func (h *HttpClient) SetEnableCookie(enable bool) *HttpClient
SetEnableCookie sets enable/disable cookiejar
func (*HttpClient) SetHeader ¶ added in v0.2.37
func (h *HttpClient) SetHeader(key, value string) *HttpClient
SetHeader 设置请求Header
func (*HttpClient) SetHost ¶ added in v0.2.37
func (h *HttpClient) SetHost(host string) *HttpClient
SetHost 设置请求Host
func (*HttpClient) SetJsonBody ¶ added in v0.2.37
func (h *HttpClient) SetJsonBody(obj any) *HttpClient
SetJsonBody 设置Json格式请求Body
func (*HttpClient) SetParam ¶ added in v0.2.37
func (h *HttpClient) SetParam(key, value string) *HttpClient
SetParam 设置请求参数
func (*HttpClient) SetParams ¶ added in v0.2.37
func (h *HttpClient) SetParams(params map[string]any) *HttpClient
SetParams 设置键值对格式请求参数
func (*HttpClient) SetProxy ¶ added in v0.2.37
func (h *HttpClient) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpClient
SetProxy 设置Http代理
func (*HttpClient) SetRetries ¶ added in v0.2.37
func (h *HttpClient) SetRetries(times int) *HttpClient
SetRetries 设置请求失败重试次数 0:不重试(默认) -1:一直重试
func (*HttpClient) SetTimeout ¶ added in v0.2.37
func (h *HttpClient) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpClient
SetTimeout 设置超时时间
func (*HttpClient) SetUserAgent ¶ added in v0.2.37
func (h *HttpClient) SetUserAgent(useragent string) *HttpClient
SetUserAgent 设置User-Agent
func (*HttpClient) SetXmlBody ¶ added in v0.2.37
func (h *HttpClient) SetXmlBody(obj any) *HttpClient
SetXmlBody 设置XML格式请求Body
func (*HttpClient) Settings ¶ added in v0.2.37
func (h *HttpClient) Settings(settings HttpSettings) *HttpClient
Settings 设置请求配置
func (*HttpClient) ToBytes ¶ added in v0.2.37
func (h *HttpClient) ToBytes() ([]byte, error)
func (*HttpClient) ToFile ¶ added in v0.2.37
func (h *HttpClient) ToFile(filename string) error
ToFile saves the body data in response to one file. it calls Response inner.
func (*HttpClient) ToJSON ¶ added in v0.2.37
func (h *HttpClient) ToJSON(v any) error
ToJSON 将响应作为json解析
func (*HttpClient) ToString ¶ added in v0.2.37
func (h *HttpClient) ToString() (string, error)
ToString 将相应转换成字符串
func (*HttpClient) ToXML ¶ added in v0.2.37
func (h *HttpClient) ToXML(v any) 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