Documentation ¶
Overview ¶
Package requester 提供网络请求简便操作
Index ¶
- Constants
- Variables
- func Fetch(method string, urlStr string, post interface{}, header map[string]string) (body []byte, err error)
- func HTTPGet(urlStr string) (body []byte, err error)
- func ParseCookieStr(cookieStr string) []*http.Cookie
- func Req(method string, urlStr string, post interface{}, header map[string]string) (resp *http.Response, err error)
- func SetGlobalProxy(proxyAddr string)
- func SetLocalTCPAddrList(ips ...string)
- func SetTCPHostBind(host, ip string)
- type ContentLengther
- type ContentTyper
- type Event
- type EventOnError
- type HTTPClient
- func (h *HTTPClient) Fetch(method string, urlStr string, post interface{}, header map[string]string) (body []byte, err error)
- func (h *HTTPClient) Req(method string, urlStr string, post interface{}, header map[string]string) (resp *http.Response, err error)
- func (h *HTTPClient) ResetCookiejar()
- func (h *HTTPClient) SetCookiejar(jar http.CookieJar)
- func (h *HTTPClient) SetGzip(b bool)
- func (h *HTTPClient) SetHTTPSecure(b bool)
- func (h *HTTPClient) SetKeepAlive(b bool)
- func (h *HTTPClient) SetProxy(proxyAddr string)
- func (h *HTTPClient) SetResponseHeaderTimeout(t time.Duration)
- func (h *HTTPClient) SetTLSHandshakeTimeout(t time.Duration)
- func (h *HTTPClient) SetTimeout(t time.Duration)
- func (h *HTTPClient) SetUserAgent(ua string)
Constants ¶
const (
// DefaultUserAgent 默认浏览器标识
DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
)
const (
// MaxDuration 最大的Duration
MaxDuration = 1<<63 - 1
)
Variables ¶
var ( // ProxyAddr 代理地址 ProxyAddr string // ErrProxyAddrEmpty 代理地址为空 ErrProxyAddrEmpty = errors.New("proxy addr is empty") )
var ( // UserAgent 浏览器标识 UserAgent = DefaultUserAgent // DefaultClient 默认 http 客户端 DefaultClient = NewHTTPClient() )
Functions ¶
func Fetch ¶
func Fetch(method string, urlStr string, post interface{}, header map[string]string) (body []byte, err error)
Fetch 参见 *HTTPClient.Fetch, 使用默认 http 客户端
func ParseCookieStr ¶
ParseCookieStr 解析 Cookie 字符串
Types ¶
type ContentLengther ¶
type ContentLengther interface {
ContentLength() int64
}
ContentLengther Content-Length 接口
type ContentTyper ¶
type ContentTyper interface {
ContentType() string
}
ContentTyper Content-Type 接口
type HTTPClient ¶
HTTPClient http client
func (*HTTPClient) Fetch ¶
func (h *HTTPClient) Fetch(method string, urlStr string, post interface{}, header map[string]string) (body []byte, err error)
Fetch 实现 http/https 访问, 根据给定的 method (GET, POST, HEAD, PUT 等等), urlStr (网址), post (post 数据), header (header 请求头数据), 进行网站访问。 返回值分别为 网站主体, 错误信息
func (*HTTPClient) Req ¶
func (h *HTTPClient) Req(method string, urlStr string, post interface{}, header map[string]string) (resp *http.Response, err error)
Req 实现 http/https 访问, 根据给定的 method (GET, POST, HEAD, PUT 等等), urlStr (网址), post (post 数据), header (header 请求头数据), 进行网站访问。 返回值分别为 *http.Response, 错误信息
func (*HTTPClient) SetCookiejar ¶
func (h *HTTPClient) SetCookiejar(jar http.CookieJar)
SetCookiejar 设置 cookie
func (*HTTPClient) SetHTTPSecure ¶
func (h *HTTPClient) SetHTTPSecure(b bool)
SetHTTPSecure 是否启用 https 安全检查, 默认不检查
func (*HTTPClient) SetKeepAlive ¶
func (h *HTTPClient) SetKeepAlive(b bool)
SetKeepAlive 设置 Keep-Alive
func (*HTTPClient) SetResponseHeaderTimeout ¶
func (h *HTTPClient) SetResponseHeaderTimeout(t time.Duration)
SetResponseHeaderTimeout 设置目标服务器响应超时时间
func (*HTTPClient) SetTLSHandshakeTimeout ¶
func (h *HTTPClient) SetTLSHandshakeTimeout(t time.Duration)
SetTLSHandshakeTimeout 设置tls握手超时时间
func (*HTTPClient) SetTimeout ¶
func (h *HTTPClient) SetTimeout(t time.Duration)
SetTimeout 设置 http 请求超时时间, 默认30s
func (*HTTPClient) SetUserAgent ¶
func (h *HTTPClient) SetUserAgent(ua string)
SetUserAgent 设置 UserAgent 浏览器标识
Directories ¶
Path | Synopsis |
---|---|
Package downloader 多线程下载器, 重构版
|
Package downloader 多线程下载器, 重构版 |
Package multipartreader helps you encode large files in MIME multipart format without reading the entire content into memory.
|
Package multipartreader helps you encode large files in MIME multipart format without reading the entire content into memory. |
Package rio rquester io 工具包
|
Package rio rquester io 工具包 |
speeds
Package speeds 速度计算工具包
|
Package speeds 速度计算工具包 |
Package uploader 上传包
|
Package uploader 上传包 |