Documentation ¶
Index ¶
- Variables
- func Get(url string, endFunc func(respData []byte, err error))
- func GetWithTimeOut(url string, timeout int, endFunc func(respData []byte, err error))
- func Post(url string, data []byte, endFunc func(respData []byte, err error))
- func PostWithBasicAuth(url string, authName string, authPwd string, data []byte, ...)
- func PostWithTimeOut(url string, timeout int, data []byte, endFunc func(respData []byte, err error))
- type HttpClient
- func (hc *HttpClient) Get(url string) ([]byte, error)
- func (hc *HttpClient) GetWithRetry(url string, maxRetry int) (string, error)
- func (hc *HttpClient) Post(url string, authName string, authPwd string, data []byte) ([]byte, error)
- func (hc *HttpClient) PostWithRetry(url string, contentType string, data []byte, maxRetry int) (string, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" DefaultTimeout = 20 // default second )
Functions ¶
func GetWithTimeOut ¶ added in v0.0.35
GetWithTimeOut Get请求,timeout 超时时间
Types ¶
type HttpClient ¶ added in v0.0.27
type HttpClient struct { Client *http.Client RequestCount int // contains filtered or unexported fields }
HttpClient 是一个高并发的 HTTP 客户端封装
func NewHttpClient ¶ added in v0.0.27
func NewHttpClient(timeout int) *HttpClient
NewHttpClient 返回一个新的 HttpClient 对象
func (*HttpClient) Get ¶ added in v0.0.27
func (hc *HttpClient) Get(url string) ([]byte, error)
Get 发送带 Header 的 GET 请求
func (*HttpClient) GetWithRetry ¶ added in v0.0.27
func (hc *HttpClient) GetWithRetry(url string, maxRetry int) (string, error)
GetWithRetry 带重试的 GET 请求,当请求失败时会自动重试,直到达到最大重试次数
func (*HttpClient) Post ¶ added in v0.0.27
func (hc *HttpClient) Post(url string, authName string, authPwd string, data []byte) ([]byte, error)
Post 发送带 Header 的 POST 请求
func (*HttpClient) PostWithRetry ¶ added in v0.0.27
func (hc *HttpClient) PostWithRetry(url string, contentType string, data []byte, maxRetry int) (string, error)
PostWithRetry 带重试的 Post 请求,当请求失败时会自动重试,直到达到最大重试次数
Click to show internal directories.
Click to hide internal directories.