gtbox_http

package
v0.1.61 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package gtbox_http http客户端工具

Index

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 Get added in v0.0.28

func Get(url string, endFunc func(respData []byte, err error))

Get Get请求

func GetWithTimeOut added in v0.0.35

func GetWithTimeOut(url string, timeout int, endFunc func(respData []byte, err error))

GetWithTimeOut Get请求,timeout 超时时间

func Post added in v0.0.28

func Post(url string, data []byte, endFunc func(respData []byte, err error))

Post Post请求

func PostWithBasicAuth added in v0.0.27

func PostWithBasicAuth(url string, authName string, authPwd string, data []byte, endFunc func(respData []byte, err error))

PostWithBasicAuth 带BasicAuth的Post

func PostWithTimeOut added in v0.0.35

func PostWithTimeOut(url string, timeout int, data []byte, endFunc func(respData []byte, err error))

PostWithTimeOut Post请求,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 请求,当请求失败时会自动重试,直到达到最大重试次数

Jump to

Keyboard shortcuts

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