Documentation ¶
Index ¶
- Constants
- Variables
- type Body
- type HeaderOption
- func Accept(accepts ...string) HeaderOption
- func AcceptLanguage(acceptLanguages ...string) HeaderOption
- func CookieAdd(cookies ...*http.Cookie) HeaderOption
- func CookieAddString(cookies ...string) HeaderOption
- func DefaultUserAgent() HeaderOption
- func HeaderDel(keys ...string) HeaderOption
- func HeaderSet(key string, values ...string) HeaderOption
- func Referer(referer string) HeaderOption
- func UserAgent(userAgent string) HeaderOption
- type Option
- type Process
- type ProcessMw
- type ProgressReport
- type Request
- func (c *Request) Body(body Body) *Request
- func (c *Request) Bytes() (data []byte, err error)
- func (c *Request) Download(fn *string, overwrite ...bool) (err error)
- func (c *Request) Form(formBody io.Reader) *Request
- func (c *Request) FormValues(formBody url.Values) *Request
- func (c *Request) HeaderWith(options ...HeaderOption) *Request
- 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) 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
Constants ¶
View Source
const ( HeaderAccept = "Accept" HeaderAcceptLanguage = "Accept-Language" HeaderUserAgent = "User-Agent" HeaderContentType = "Content-Type" HeaderReferer = "Referer" HeaderCacheControl = "Cache-Control" // no-cache HeaderPragma = "Pragma" // no-cache )
View Source
const ( HeaderRequestCookie = "Cookie" // Request Cookie HeaderResponseCookie = "Set-Cookie" // Response Cookie )
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 DownloadTempExt = ".uxdt"
View Source
const Version = "0.0.1"
Variables ¶
View Source
var ( MacChromeAgent = UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36") MacFirefoxAgent = UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:65.0) Gecko/20100101 Firefox/65.0") MacSafariAgent = UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.3 Safari/605.1.15") 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") WindowsChromeAgent = UserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36") 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") WindowsIEAgent = UserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko") IOSChromeAgent = UserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/31.0.1650.18 Mobile/11B554a Safari/8536.25") IOSSafariAgent = UserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4") IOSEdgAgent = 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") AndroidChromeAgent = UserAgent("Mozilla/5.0 (Linux; Android 11; SM-G9910) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36") AndroidWebkitAgent = UserAgent("Mozilla/5.0 (Linux; Android 11; SM-G9910) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30") AndroidEdgeAgent = UserAgent("Mozilla/5.0 (Linux; Android 11; SM-G9910) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Mobile Safari/537.36 Edge/95.0.1020.55") )
View Source
var ( // 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("*/*") // NoCache 无缓存 NoCache = HeaderOption(func(headers http.Header) { headers.Set(HeaderCacheControl, "no-cache") headers.Set(HeaderPragma, "no-cache") }) )
View Source
var ProcessNil = func(resp *http.Response) error { return nil }
Functions ¶
This section is empty.
Types ¶
type HeaderOption ¶
一些特定方法的定义
func AcceptLanguage ¶
func AcceptLanguage(acceptLanguages ...string) HeaderOption
AcceptLanguage 接受语言
func CookieAddString ¶
func CookieAddString(cookies ...string) HeaderOption
CookieAddString 添加Cookie到请求
func DefaultUserAgent ¶
func DefaultUserAgent() HeaderOption
type ProcessMw ¶
func Progress ¶
func Progress(report ProgressReport, reportInterval ...time.Duration) ProcessMw
Progress 下载进度, reportInterval 报告的时间间隔, 最小1秒, 默认2秒
func ReadCookie ¶
ReadCookie 从响应读取Cookie
type ProgressReport ¶
ProgressReport 进度报告方法
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request 请求构造
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.