http_client

package
v0.0.0-...-72e02b7 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpClient

type HttpClient struct {
	Header        http.Header
	Client        *http.Client
	RetryTimes    int //重试次数
	RetryInterval time.Duration
}

func NewHttpClient

func NewHttpClient(retryTimes int, retryInterval, timeout time.Duration) HttpClient

func (*HttpClient) AutoRedirect

func (self *HttpClient) AutoRedirect(is bool)

控制是否需要重定向,因httpclient重定向后不会带cookie,所以有时需要手动重定向

func (*HttpClient) DownloadFile

func (self *HttpClient) DownloadFile(requestUrl, path string) (err error)

从指定链接下载文件到本地

func (*HttpClient) Get

func (self *HttpClient) Get(requestUrl string) (*http.Response, error)

make a http get request

func (*HttpClient) GetBody

func (self *HttpClient) GetBody(requestUrl string) ([]byte, error)

make a http get request, and return the string body

func (*HttpClient) GetWithCookies

func (self *HttpClient) GetWithCookies(requestUrl string, cookies []*http.Cookie) (*http.Response, error)

make a http get request with cookies

func (*HttpClient) Post

func (self *HttpClient) Post(requestUrl, contentType string, postBody io.Reader) ([]byte, error)

make a http post request, and return the []byte body

func (*HttpClient) PostForm

func (self *HttpClient) PostForm(requestUrl string, data url.Values) ([]byte, error)

func (*HttpClient) PostJson

func (self *HttpClient) PostJson(requestUrl string, data interface{}) ([]byte, error)

func (*HttpClient) PostJsonWithRetry

func (self *HttpClient) PostJsonWithRetry(requestUrl string, data interface{}) ([]byte, error)

post json,带重试

func (*HttpClient) SetHttpProxy

func (self *HttpClient) SetHttpProxy(httpProxy string)

func (*HttpClient) SetRetryInterval

func (self *HttpClient) SetRetryInterval(i time.Duration) *HttpClient

func (*HttpClient) SetRetryTimes

func (self *HttpClient) SetRetryTimes(n int)

func (*HttpClient) SetTimeout

func (self *HttpClient) SetTimeout(timeout time.Duration)

func (*HttpClient) Upload

func (self *HttpClient) Upload(requestUrl, fieldName, filePath string, params map[string]string) ([]byte, error)

上传

Jump to

Keyboard shortcuts

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