Documentation ¶
Index ¶
- Variables
- func DefaultHeaders() http.Header
- func ReadRequest(b *bufio.Reader) (*http.Request, error)
- type AddrType
- type Client
- func (obj *Client) ClearCookies()
- func (obj *Client) Close()
- func (obj *Client) CloseIdleConnections()
- func (obj *Client) Connect(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Cookies(href string, cookies ...any) (Cookies, error)
- func (obj *Client) Delete(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Get(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Head(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Options(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Patch(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Post(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Put(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Request(preCtx context.Context, method string, href string, options ...RequestOption) (resp *Response, err error)
- func (obj *Client) SetGetProxy(getProxy func(ctx context.Context, url *url.URL) (string, error))
- func (obj *Client) SetProxy(proxy string) error
- func (obj *Client) Trace(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- type ClientOption
- type Cookies
- type DialClient
- func (obj *DialClient) AddProxyTls(ctx context.Context, conn net.Conn, host string) (net.Conn, error)
- func (obj *DialClient) AddTls(ctx context.Context, conn net.Conn, host string, disHttp bool) (tlsConn *tls.Conn, err error)
- 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) DialContextWithProxy(ctx context.Context, netword string, scheme string, addr string, host string, ...) (net.Conn, error)
- func (obj *DialClient) Dialer() *net.Dialer
- func (obj *DialClient) DnsDialContext(ctx context.Context, netword string, addr string) (net.Conn, error)
- func (obj *DialClient) GetProxy(ctx context.Context, href *url.URL) (*url.URL, error)
- func (obj *DialClient) Proxy() *url.URL
- func (obj *DialClient) SetGetProxy(getProxy func(ctx context.Context, url *url.URL) (string, error))
- func (obj *DialClient) SetProxy(proxy string) error
- func (obj *DialClient) Socks5Proxy(ctx context.Context, network string, addr string, proxyUrl *url.URL) (conn net.Conn, err error)
- type DialOption
- type Event
- type File
- type Jar
- type RequestDebug
- type RequestOption
- type Response
- func Connect(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func Delete(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func Get(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func Head(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func Options(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func Patch(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func Post(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func Put(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func Request(preCtx context.Context, method string, href string, options ...RequestOption) (*Response, error)
- func Trace(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Response) Close() error
- func (obj *Response) Content() []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) Html() *bs4.Client
- func (obj *Response) Json(vals ...any) (gjson.Result, error)
- 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) SetContent(val []byte)
- func (obj *Response) SseClient() *SseClient
- func (obj *Response) Status() string
- func (obj *Response) StatusCode() int
- func (obj *Response) Text() string
- func (obj *Response) Url() *url.URL
- func (obj *Response) WebSocket() *websocket.Conn
- type ResponseDebug
- 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 ¶
func DefaultHeaders ¶
请求操作========================================================================= start
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(preCtx context.Context, options ...ClientOption) (*Client, error)
新建一个请求客户端,发送请求必须创建哈
func (*Client) Request ¶
func (obj *Client) Request(preCtx context.Context, method string, href string, options ...RequestOption) (resp *Response, err error)
发送请求
func (*Client) SetGetProxy ¶
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 time.Duration //第一个response headers 接收超时时间,default:30 DisCookie bool //关闭cookies管理 DisCompression bool //关闭请求头中的压缩功能 LocalAddr string //本地网卡出口ip IdleConnTimeout time.Duration //空闲连接在连接池中的超时时间,default:90 KeepAlive time.Duration //keepalive保活检测定时,default:30 DnsCacheTime time.Duration //dns解析缓存时间60*30 AddrType AddrType //优先使用的addr 类型 GetAddrType func(string) AddrType Dns string //dns Ja3 bool //开启ja3 Ja3Spec ja3.Ja3Spec //指定ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成 H2Ja3 bool //开启h2指纹 H2Ja3Spec ja3.H2Ja3Spec //h2指纹 RedirectNum int //重定向次数,小于0为禁用,0:不限制 DisDecode bool //关闭自动编码 DisRead bool //关闭默认读取请求体 DisUnZip bool //变比自动解压 TryNum int64 //重试次数 OptionCallBack func(context.Context, *RequestOption) error //请求参数回调,用于对请求参数进行修改。返回error,中断重试请求,返回nil继续 ResultCallBack func(context.Context, *Response) error //结果回调,用于对结果进行校验。返回nil,直接返回,返回err的话,如果有errCallBack 走errCallBack,没有继续try ErrCallBack func(context.Context, error) error //错误回调,返回error,中断重试请求,返回nil继续 Timeout time.Duration //请求超时时间 Headers any //请求头 Bar bool //是否开启bar }
type DialClient ¶
type DialClient struct {
// contains filtered or unexported fields
}
func NewDail ¶
func NewDail(ctx context.Context, option DialOption) (*DialClient, error)
func (*DialClient) AddProxyTls ¶
func (*DialClient) DialContext ¶
func (*DialClient) DialContextWithProxy ¶
func (*DialClient) Dialer ¶
func (obj *DialClient) Dialer() *net.Dialer
func (*DialClient) DnsDialContext ¶
func (*DialClient) Proxy ¶
func (obj *DialClient) Proxy() *url.URL
func (*DialClient) SetGetProxy ¶
func (*DialClient) SetProxy ¶
func (obj *DialClient) SetProxy(proxy string) error
type DialOption ¶
type DialOption struct { TLSHandshakeTimeout time.Duration DnsCacheTime time.Duration KeepAlive time.Duration 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.Ja3Spec //指定ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成 ProxyJa3 bool //代理是否启用ja3 ProxyJa3Spec ja3.Ja3Spec //指定代理ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成 Dns string //dns }
type File ¶
type File struct { Key string //字段的key Name string //文件名 Content []byte //文件的内容 Type string //文件类型 }
构造一个文件
type Jar ¶
type Jar struct {
// contains filtered or unexported fields
}
func (*Jar) ClearCookies ¶
func (obj *Jar) ClearCookies()
type RequestDebug ¶
type RequestDebug struct { Url *url.URL Method string Header http.Header Proto string // contains filtered or unexported fields }
func (*RequestDebug) Bytes ¶
func (obj *RequestDebug) Bytes() []byte
func (*RequestDebug) String ¶
func (obj *RequestDebug) String() string
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 time.Duration //请求超时时间 Headers any //请求头,支持:json,map,header Cookies any // cookies,支持json,map,str,http.Header Files []File //发送multipart/form-data,文件上传 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 ContentType string //headers 中Content-Type 的值 Raw any //不设置context-type,支持string,[]bytes,json,map TempData map[string]any //临时变量,用于回调存储或自由度更高的用法 DisCookie bool //关闭cookies管理,这个请求不用cookies池 DisDecode bool //关闭自动解码 Bar bool //是否开启bar DisProxy bool //是否关闭代理,强制关闭代理 TryNum int64 //重试次数 OptionCallBack func(context.Context, *RequestOption) error //请求参数回调,用于对请求参数进行修改。返回error,中断重试请求,返回nil继续 ResultCallBack func(context.Context, *Response) error //结果回调,用于对结果进行校验。返回nil,直接返回,返回err的话,如果有errCallBack 走errCallBack,没有继续try ErrCallBack func(context.Context, error) error //错误回调,返回error,中断重试请求,返回nil继续 RequestCallBack func(context.Context, *RequestDebug) error //request回调,用于定位bug,正常请求不要设置这个函数 ResponseCallBack func(context.Context, *ResponseDebug) error //response回调,用于定位bug,正常请求不要设置这个函数 Jar *Jar //自定义临时cookies 管理 RedirectNum int //重定向次数,小于零 关闭重定向 DisRead bool //关闭默认读取请求体,不会主动读取body里面的内容,需用你自己读取 DisUnZip bool //关闭自动解压 WsOption websocket.Option //websocket option,使用websocket 请求的option // contains filtered or unexported fields }
请求参数选项
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func (*Response) ContentEncoding ¶
获取headers 的Content-Encoding
type ResponseDebug ¶
type ResponseDebug struct { Proto string Status string Header http.Header // contains filtered or unexported fields }
func (*ResponseDebug) Bytes ¶
func (obj *ResponseDebug) Bytes() []byte
func (*ResponseDebug) String ¶
func (obj *ResponseDebug) String() string
Click to show internal directories.
Click to hide internal directories.