Documentation
¶
Index ¶
- type CookieJar
- type HttpClient
- func (this *HttpClient) ClearProxy() *HttpClient
- func (this *HttpClient) CustomizeTransport(f func(tr *http.Transport)) *HttpClient
- func (this *HttpClient) SetCookieJar(j *CookieJar) *HttpClient
- func (this *HttpClient) SetProxy(proxyUrl string) *HttpClient
- func (this *HttpClient) SetRedirect(f func(req *http.Request, via []*http.Request) error) *HttpClient
- func (this *HttpClient) SetSkipVerify(isSkipVerify bool) *HttpClient
- func (this *HttpClient) SetTimeout(t time.Duration) *HttpClient
- type Request
- func (this *Request) End() (*http.Response, string, error)
- func (this *Request) EndByte() (*http.Response, []byte, error)
- func (this *Request) EndFile(savePath, saveFileName string) (*http.Response, error)
- func (this *Request) GetError() error
- func (this *Request) GetResponse() *http.Response
- func (this *Request) Send(ctxs ...context.Context) *Request
- func (this *Request) SetBasicAuth(username, password string) *Request
- func (this *Request) SetBody(body body.Body) *Request
- func (this *Request) SetClient(client *HttpClient) *Request
- func (this *Request) SetCookies(cookies *[]*http.Cookie) *Request
- func (this *Request) SetDebug(d bool) *Request
- func (this *Request) SetHeader(name, value string) *Request
- func (this *Request) SetMethod(name string) *Request
- func (this *Request) SetParam(name, value string) *Request
- func (this *Request) SetUrl(url string) *Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CookieJar ¶
type CookieJar struct {
// contains filtered or unexported fields
}
func NewCookieJar ¶
func NewCookieJar() *CookieJar
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient 封装了 http.Client 与 http.Transport 是构建 Request 的基础客户端对象
func (*HttpClient) ClearProxy ¶
func (this *HttpClient) ClearProxy() *HttpClient
ClearProxy 清除当前代理配置,使请求不再通过代理服务器发送
func (*HttpClient) CustomizeTransport ¶ added in v1.1.2
func (this *HttpClient) CustomizeTransport(f func(tr *http.Transport)) *HttpClient
CustomizeTransport 允许自定义底层 http.Transport 的所有字段
func (*HttpClient) SetCookieJar ¶
func (this *HttpClient) SetCookieJar(j *CookieJar) *HttpClient
SetCookieJar 为客户端设置 CookieJar,用于管理 Cookie CookieJar 会自动存储与发送 Cookie
func (*HttpClient) SetProxy ¶
func (this *HttpClient) SetProxy(proxyUrl string) *HttpClient
SetProxy 设置客户端的代理服务器地址 参数 proxyUrl 为代理地址,如 "http://127.0.0.1:1080" 设置后所有请求将通过代理发送
func (*HttpClient) SetRedirect ¶
func (this *HttpClient) SetRedirect(f func(req *http.Request, via []*http.Request) error) *HttpClient
SetRedirect 设置客户端的重定向策略 调用者需传入一个 CheckRedirect 回调函数,用于处理 3xx 重定向
func (*HttpClient) SetSkipVerify ¶
func (this *HttpClient) SetSkipVerify(isSkipVerify bool) *HttpClient
SetSkipVerify 设置是否跳过 TLS 证书验证 参数 isSkipVerify 为 true 时不验证服务端证书
func (*HttpClient) SetTimeout ¶
func (this *HttpClient) SetTimeout(t time.Duration) *HttpClient
SetTimeout 设置客户端总请求超时时间 参数 t 为超时值,例如 30 * time.Second
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request 封装了 HTTP 请求构建和发送的逻辑
func NewRequest ¶
func NewRequest(client *HttpClient) *Request
NewRequest 创建一个新的 Request 对象,默认使用 GET 方法
func (*Request) GetResponse ¶
GetResponse 返回 HTTP 响应对象
func (*Request) SetBasicAuth ¶
SetBasicAuth 设置 HTTP Basic Auth 认证
func (*Request) SetClient ¶
func (this *Request) SetClient(client *HttpClient) *Request
SetClient 替换请求使用的 HttpClient
func (*Request) SetCookies ¶
SetCookies 设置请求的 Cookie 列表