requester

package
v0.0.0-...-76ae43c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UserAgent 浏览器标识
	UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36"

	//DefaultClient 默认 http 客户端
	DefaultClient = NewHTTPClient()
)

Functions

func Fetch

func Fetch(method string, urlStr string, post interface{}, header map[string]string) ([]byte, error)

Fetch 参见 *HTTPClient.Fetch, 使用默认 http 客户端

func HTTPGet

func HTTPGet(urlStr string) ([]byte, error)

HTTPGet 简单实现 http 访问 GET 请求

func Headers

func Headers(url string) (http.Header, error)

Headers return the HTTP Headers of the url

func Req

func Req(method string, urlStr string, post interface{}, header map[string]string) (*http.Response, error)

Req 参见 *HTTPClient.Req, 使用默认 http 客户端

func Size

func Size(url string) (int, error)

Size get size of the url

Types

type HTTPClient

type HTTPClient struct {
	http.Client
	UserAgent string
}

HTTPClient client

func NewHTTPClient

func NewHTTPClient() *HTTPClient

NewHTTPClient new client

func (*HTTPClient) Fetch

func (h *HTTPClient) Fetch(method string, urlStr string, post interface{}, header map[string]string) ([]byte, error)

Fetch 实现 http/https 访问, 根据给定的 method (GET, POST, HEAD, PUT 等等), urlStr (网址), post (post 数据), header (header 请求头数据), 进行网站访问。 返回值分别为 []byte, 错误信息

func (*HTTPClient) Req

func (h *HTTPClient) Req(method string, urlStr string, post interface{}, header map[string]string) (*http.Response, error)

Req 实现 http/https 访问, 根据给定的 method (GET, POST, HEAD, PUT 等等), urlStr (网址), post (post 数据), header (header 请求头数据), 进行网站访问。 返回值分别为 *http.Response, 错误信息

func (*HTTPClient) ResetCookieJar

func (h *HTTPClient) ResetCookieJar()

ResetCookieJar 重置cookie jar

func (*HTTPClient) SetCookiejar

func (h *HTTPClient) SetCookiejar(jar http.CookieJar)

SetCookiejar 设置 Cookie

func (*HTTPClient) SetTimeout

func (h *HTTPClient) SetTimeout(t time.Duration)

SetTimeout 设置超时时间

func (*HTTPClient) SetUserAgent

func (h *HTTPClient) SetUserAgent(ua string)

SetUserAgent 设置 UserAgent 浏览器标识

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL