Documentation ¶
Index ¶
- Constants
- type HttpClient
- func (self *HttpClient) AutoRedirect(is bool)
- func (self *HttpClient) DownloadFile(requestUrl, path string) (err error)
- func (self *HttpClient) Get(requestUrl string) (*http.Response, error)
- func (self *HttpClient) GetBody(requestUrl string) ([]byte, error)
- func (self *HttpClient) GetWithCookies(requestUrl string, cookies []*http.Cookie) (*http.Response, error)
- func (self *HttpClient) Post(requestUrl, contentType string, postBody io.Reader) ([]byte, error)
- func (self *HttpClient) PostForm(requestUrl string, data url.Values) ([]byte, error)
- func (self *HttpClient) PostJson(requestUrl string, data interface{}) ([]byte, error)
- func (self *HttpClient) PostJsonWithRetry(requestUrl string, data interface{}) ([]byte, error)
- func (self *HttpClient) SetHttpProxy(httpProxy string)
- func (self *HttpClient) SetRetryInterval(i time.Duration) *HttpClient
- func (self *HttpClient) SetRetryTimes(n int)
- func (self *HttpClient) SetTimeout(timeout time.Duration)
- func (self *HttpClient) Upload(requestUrl, fieldName, filePath string, params map[string]string) ([]byte, error)
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) 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)
Click to show internal directories.
Click to hide internal directories.