Documentation ¶
Index ¶
- Constants
- Variables
- type Body
- type HeaderOption
- func Accept(accept string) HeaderOption
- func AcceptEncoding(acceptEncodings ...string) HeaderOption
- func AcceptLanguage(acceptLanguages ...string) HeaderOption
- func HeaderDel(keys ...string) HeaderOption
- func HeaderSet(key string, values ...string) HeaderOption
- func Referer(referer string) HeaderOption
- func UserAgent(userAgent string) HeaderOption
- type MultipartBody
- func (m *MultipartBody) Body() (contentType string, body io.Reader, err error)
- func (m *MultipartBody) File(getFile func() (field, filename string, fileBody io.ReadCloser, err error)) *MultipartBody
- func (m *MultipartBody) LocalFile(field string, filename string) *MultipartBody
- func (m *MultipartBody) Params(params url.Values) *MultipartBody
- func (m *MultipartBody) WaitEnd(ctx context.Context) error
- type Option
- type Process
- type ProcessMw
- type Request
- func Default(ctx context.Context) *Request
- func IPhoneEdge(ctx context.Context) *Request
- func MacEdge(ctx context.Context) *Request
- func New(ctx context.Context, options ...Option) *Request
- func NewBrowser(ctx context.Context, userAgent HeaderOption) *Request
- func WindowsEdge(ctx context.Context) *Request
- func (c *Request) Bytes() (data []byte, err error)
- func (c *Request) Download(fn string) (err error)
- func (c *Request) HeaderWith(options ...HeaderOption) *Request
- func (c *Request) JSON(out any) (data []byte, err error)
- func (c *Request) Method(method string) *Request
- func (c *Request) Process(process Process) error
- func (c *Request) ProcessWith(mws ...ProcessMw) *Request
- func (c *Request) Query(query string) *Request
- func (c *Request) SendBody(body Body) *Request
- func (c *Request) SendForm(v any) *Request
- func (c *Request) SendJSON(v any) *Request
- func (c *Request) SendXML(v any) *Request
- func (c *Request) TryAt(times ...time.Duration) *Request
- func (c *Request) Url(url string) *Request
- func (c *Request) UseClient(client *http.Client) *Request
- func (c *Request) With(options ...Option) *Request
- func (c *Request) XML(out any) (data []byte, err error)
- func (c *Request) YAML(out any) (data []byte, err error)
Constants ¶
View Source
const ( HeaderAccept = "Accept" HeaderAcceptLanguage = "Accept-Language" HeaderAcceptEncoding = "Accept-Encoding" HeaderUserAgent = "User-Agent" HeaderContentType = "Content-Type" HeaderReferer = "Referer" HeaderCacheControl = "Cache-Control" // no-cache HeaderPragma = "Pragma" // no-cache )
View Source
const ( MethodGet = http.MethodGet MethodHead = http.MethodHead MethodPost = http.MethodPost MethodPut = http.MethodPut MethodPatch = http.MethodPatch MethodDelete = http.MethodDelete MethodConnect = http.MethodConnect MethodOptions = http.MethodOptions MethodTrace = http.MethodTrace )
View Source
const HeaderContentEncoding = "Content-Encoding"
View Source
const Version = "0.0.1"
Variables ¶
View Source
var ( // MacEdgeAgent Mac Edge 浏览器的 UserAgent MacEdgeAgent = UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43") // IPhoneAgent IPhone Edge 浏览器的 UserAgent IPhoneAgent = UserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/96.0.4664.55") // WindowsEdgeAgent Windows Edge 浏览器的 UserAgent WindowsEdgeAgent = UserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43") )
View Source
var ( // NoCache 无缓存 NoCache = HeaderOption(func(headers http.Header) { headers.Set(HeaderCacheControl, "no-cache") headers.Set(HeaderPragma, "no-cache") }) // AcceptAllEncodings 接受所有的编码格式 AcceptAllEncodings = AcceptEncoding("zstd", "br", "gzip", "deflate", "snappy", "s2") // DefaultEncodings 默认接受所有的编码格式 DefaultEncodings = AcceptEncoding("gzip", "deflate", "br") // AcceptChinese 接受中文 AcceptChinese = AcceptLanguage("zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,zh-TW;q=0.5") // AcceptHTML 接受网页浏览器格式 AcceptHTML = Accept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9") // AcceptJSON 接受JSON格式 AcceptJSON = Accept("application/json") // AcceptXML 接受XML格式 AcceptXML = Accept("application/xml,text/xml") // AcceptAny 接受任意格式 AcceptAny = Accept("*/*") )
View Source
var ProcessNil = func(resp *http.Response, body io.ReadCloser) error { return nil }
Functions ¶
This section is empty.
Types ¶
type HeaderOption ¶
一些特定方法的定义
var DefaultUserAgent HeaderOption
func AcceptEncoding ¶
func AcceptEncoding(acceptEncodings ...string) HeaderOption
AcceptEncoding 接受编码
func AcceptLanguage ¶
func AcceptLanguage(acceptLanguages ...string) HeaderOption
AcceptLanguage 接受语言
type MultipartBody ¶
type MultipartBody struct {
// contains filtered or unexported fields
}
func Multipart ¶
func Multipart() *MultipartBody
func (*MultipartBody) Body ¶
func (m *MultipartBody) Body() (contentType string, body io.Reader, err error)
func (*MultipartBody) File ¶
func (m *MultipartBody) File(getFile func() (field, filename string, fileBody io.ReadCloser, err error)) *MultipartBody
func (*MultipartBody) LocalFile ¶
func (m *MultipartBody) LocalFile(field string, filename string) *MultipartBody
func (*MultipartBody) Params ¶
func (m *MultipartBody) Params(params url.Values) *MultipartBody
type Process ¶
type Process = func(resp *http.Response, body io.ReadCloser) error // 响应处理器
func CharsetDecode ¶
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request 请求构造
func NewBrowser ¶
func NewBrowser(ctx context.Context, userAgent HeaderOption) *Request
NewBrowser 浏览器
func (*Request) HeaderWith ¶
func (c *Request) HeaderWith(options ...HeaderOption) *Request
HeaderWith 设置请求头
func (*Request) ProcessWith ¶
ProcessWith 在处理之前的预处理
Source Files ¶
Click to show internal directories.
Click to hide internal directories.