Documentation
¶
Index ¶
- Variables
- type AddrType
- type Client
- func (obj *Client) ClearCookies() error
- func (obj *Client) Clone() *Client
- func (obj *Client) Close()
- func (obj *Client) CloseIdleConnections()
- func (obj *Client) Closed() bool
- func (obj *Client) Cookies(href string, cookies ...*http.Cookie) Cookies
- func (obj *Client) Get(href string, options ...RequestOption) (resp *Response, err error)
- func (obj *Client) Request(method string, href string, options ...RequestOption) (resp *Response, err error)
- func (obj *Client) RequestWithContext(preCtx context.Context, method string, href string, options ...RequestOption) (resp *Response, err error)
- func (obj *Client) Reset() error
- type ClientOption
- type Cookies
- type DialClient
- func (obj *DialClient) AddrToIp(ctx context.Context, addr string) (string, error)
- func (obj *DialClient) DialContext(ctx context.Context, netword string, addr string) (net.Conn, error)
- func (obj *DialClient) DialContextForProxy(ctx context.Context, netword string, scheme string, addr string, host string, ...) (net.Conn, error)
- func (obj *DialClient) DialTlsProxyContext(ctx context.Context, netword string, addr string, host string) (net.Conn, error)
- func (obj *DialClient) DnsDialContext(ctx context.Context, netword string, addr string) (net.Conn, error)
- func (obj *DialClient) GetProxy(ctx context.Context, url *url.URL) (*url.URL, error)
- func (obj *DialClient) Http2HttpProxy(ctx context.Context, network string, proxyUrl *url.URL) (conn net.Conn, err error)
- func (obj *DialClient) Http2HttpsProxy(ctx context.Context, network string, addr string, host string, ...) (conn net.Conn, err error)
- func (obj *DialClient) Http2Socks5Proxy(ctx context.Context, network string, addr string, proxyUrl *url.URL) (conn net.Conn, err error)
- func (obj *DialClient) Https2HttpProxy(ctx context.Context, network string, addr string, host string, ...) (conn net.Conn, err error)
- func (obj *DialClient) Https2HttpsProxy(ctx context.Context, network string, addr string, host string, ...) (conn net.Conn, err error)
- func (obj *DialClient) Https2Socks5Proxy(ctx context.Context, network string, addr string, host string, ...) (conn net.Conn, err error)
- type DialOption
- type Event
- type File
- type RequestOption
- type Response
- func Get(href string, options ...RequestOption) (resp *Response, err error)
- func Request(method string, href string, options ...RequestOption) (resp *Response, err error)
- func RequestWithContext(preCtx context.Context, method string, href string, options ...RequestOption) (resp *Response, err error)
- func (obj *Response) Close() error
- func (obj *Response) Content(val ...[]byte) []byte
- func (obj *Response) ContentEncoding() string
- func (obj *Response) ContentLength() int64
- func (obj *Response) ContentType() string
- func (obj *Response) Cookies() Cookies
- func (obj *Response) Decode(encoding string)
- func (obj *Response) Headers() http.Header
- func (obj *Response) Json(path ...string) gjson.Result
- func (obj *Response) Location() (*url.URL, error)
- func (obj *Response) Map() map[string]any
- func (obj *Response) Read(con []byte) (int, error)
- func (obj *Response) Response() *http.Response
- func (obj *Response) SseClient() *SseClient
- func (obj *Response) Status() string
- func (obj *Response) StatusCode() int
- func (obj *Response) Text(val ...string) string
- func (obj *Response) Url() *url.URL
- func (obj *Response) WebSocket() *websocket.Conn
- type SseClient
Constants ¶
This section is empty.
Variables ¶
View Source
var AcceptLanguage = `"zh-CN,zh;q=0.9"`
View Source
var (
ErrFatal = errors.New("致命错误")
)
View Source
var UserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36`
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { RedirectNum int // 重定向次数 DisDecode bool // 关闭自动编码 DisRead bool // 关闭默认读取请求体 DisUnZip bool // 变比自动解压 TryNum int64 // 重试次数 BeforCallBack func(context.Context, *RequestOption) error // 请求前回调的方法 AfterCallBack func(context.Context, *Response) error // 请求后回调的方法 ErrCallBack func(context.Context, error) bool // 请求error回调 Timeout int64 // 请求超时时间 Headers any // 请求头 // contains filtered or unexported fields }
func NewClient ¶
func NewClient(clientOptinos ...ClientOption) (*Client, error)
NewClient 新建一个请求客户端,发送请求必须创建哈
func NewClientWithContext ¶
func NewClientWithContext(preCtx context.Context, clientOptinos ...ClientOption) (*Client, error)
NewClientWithContext 新建一个请求客户端,发送请求必须创建哈
func (*Client) CloseIdleConnections ¶
func (obj *Client) CloseIdleConnections()
CloseIdleConnections 关闭客户端中的空闲连接
func (*Client) Get ¶ added in v0.0.2
func (obj *Client) Get(href string, options ...RequestOption) (resp *Response, err error)
Get 发送GET请求
func (*Client) Request ¶
func (obj *Client) Request(method string, href string, options ...RequestOption) (resp *Response, err error)
Request 发送请求
func (*Client) RequestWithContext ¶
type ClientOption ¶
type ClientOption struct { GetProxy func(ctx context.Context, url *url.URL) (string, error) // 根据url 返回代理,支持https,http,socks5 代理协议 Proxy string // 设置代理,支持https,http,socks5 代理协议 TLSHandshakeTimeout time.Duration // tls 超时时间,default:15 ResponseHeaderTimeout int64 // 第一个response headers 接收超时时间,default:30 DisCookie bool // 关闭cookies管理 DisAlive bool // 关闭长连接 DisCompression bool // 关闭请求头中的压缩功能 LocalAddr string // 本地网卡出口ip IdleConnTimeout int64 // 空闲连接在连接池中的超时时间,default:30 KeepAlive int64 // keepalive保活检测定时,default:15 DnsCacheTime int64 // dns解析缓存时间60*30 DisDnsCache bool // 是否关闭dns 缓存,影响dns 解析 AddrType AddrType // 优先使用的addr 类型 GetAddrType func(string) AddrType // 地址类型 Dns string // dns Ja3 bool // 开启ja3 Ja3Spec ja3.ClientHelloSpec // 指定ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成 H2Ja3 bool // 开启h2指纹 H2Ja3Spec ja3.H2Ja3Spec // h2指纹 }
type DialClient ¶
type DialClient struct {
// contains filtered or unexported fields
}
func (*DialClient) DialContext ¶
func (*DialClient) DialContextForProxy ¶
func (*DialClient) DialTlsProxyContext ¶
func (*DialClient) DnsDialContext ¶
func (*DialClient) Http2HttpProxy ¶
func (*DialClient) Http2HttpsProxy ¶
func (*DialClient) Http2Socks5Proxy ¶
func (*DialClient) Https2HttpProxy ¶
func (*DialClient) Https2HttpsProxy ¶
type DialOption ¶
type DialOption struct { TLSHandshakeTimeout time.Duration DnsCacheTime int64 KeepAlive int64 GetProxy func(ctx context.Context, url *url.URL) (string, error) Proxy string // 代理 LocalAddr string // 使用本地网卡 AddrType AddrType // 优先使用的地址类型,ipv4,ipv6 ,或自动选项 GetAddrType func(string) AddrType Ja3 bool // 是否启用ja3 Ja3Spec ja3.ClientHelloSpec // 指定ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成 DisDnsCache bool // 是否关闭dns 缓存 Dns string // dns }
type File ¶
type File struct { Key string // 字段的key Name string // 文件名 Content []byte // 文件的内容 Type string // 文件类型 }
File 构造一个文件
type RequestOption ¶
type RequestOption struct { Method string // method Url *url.URL // 请求的url Host string // 网站的host Proxy string // 代理,支持http,https,socks5协议代理,例如:http://127.0.0.1:7005 Timeout int64 // 请求超时时间 Headers any // 请求头,支持:json,map,header Cookies any // cookies,支持json,map,str Files []File // 文件 Params any // url 中的参数,用以拼接url,支持json,map Form any // 发送multipart/form-data,适用于文件上传,支持json,map Data any // 发送application/x-www-form-urlencoded,适用于key,val,支持string,[]bytes,json,map Body io.Reader Json any // 发送application/json,支持:string,[]bytes,json,map Text any // 发送text/xml,支持string,[]bytes,json,map Raw any // 不设置context-type,支持string,[]bytes,json,map TempData any // 临时变量,用于回调存储或自由度更高的用法 DisCookie bool // 关闭cookies管理,这个请求不用cookies池 DisDecode bool // 关闭自动解码 DisProxy bool // 是否关闭代理,强制关闭代理 Ja3 bool // 是否开启ja3 Ja3Spec ja3.ClientHelloSpec // 指定ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成 TryNum int64 // 重试次数 BeforCallBack func(context.Context, *RequestOption) error // 请求之前回调 AfterCallBack func(context.Context, *Response) error // 请求之后回调 ErrCallBack func(context.Context, error) bool // 返回true 中断重试请求 RedirectNum int // 重定向次数,小于零 关闭重定向 DisAlive bool // 关闭长连接,这次请求不会复用之前的连接 DisRead bool // 关闭默认读取请求体,不会主动读取body里面的内容,需用你自己读取 DisUnZip bool // 关闭自动解压 WsOption websocket.Option // websocket option,使用websocket 请求的option // contains filtered or unexported fields }
RequestOption 请求参数选项
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func Get ¶ added in v0.0.2
func Get(href string, options ...RequestOption) (resp *Response, err error)
Get 发送GET请求
func Request ¶ added in v0.0.2
func Request(method string, href string, options ...RequestOption) (resp *Response, err error)
Request 发送请求
func RequestWithContext ¶ added in v0.0.2
func (*Response) ContentEncoding ¶
ContentEncoding 获取headers 的Content-Encoding
func (*Response) ContentLength ¶
ContentLength 获取response 的内容长度
func (*Response) ContentType ¶
ContentType 获取headers 的Content-Type
Directories
¶
Path | Synopsis |
---|---|
Package http2 implements the HTTP/2 protocol.
|
Package http2 implements the HTTP/2 protocol. |
h2c
Package h2c implements the unencrypted "h2c" form of HTTP/2.
|
Package h2c implements the unencrypted "h2c" form of HTTP/2. |
h2i
The h2i command is an interactive HTTP/2 console.
|
The h2i command is an interactive HTTP/2 console. |
hpack
Package hpack implements HPACK, a compression format for efficiently representing HTTP header fields in the context of HTTP/2.
|
Package hpack implements HPACK, a compression format for efficiently representing HTTP header fields in the context of HTTP/2. |
Click to show internal directories.
Click to hide internal directories.