libhttp

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpClient added in v0.2.37

type HttpClient struct {
	// contains filtered or unexported fields
}

HttpClient

func Delete

func Delete(url string) *HttpClient

Delete

func Get

func Get(url string) *HttpClient

Get

func Head(url string) *HttpClient

Head

func NewClient added in v0.2.37

func NewClient(rawUrl, method string) *HttpClient

NewClient http客户端

func Post

func Post(url string) *HttpClient

Post

func Put

func Put(url string) *HttpClient

Put

func (*HttpClient) AddCookie added in v0.2.37

func (h *HttpClient) AddCookie(cookie *http.Cookie) *HttpClient

AddCookie 添加请求Cookie

func (*HttpClient) AddParam added in v0.2.37

func (h *HttpClient) AddParam(key, value string) *HttpClient

AddParam 增加请求参数

func (*HttpClient) GetResponse added in v0.2.37

func (h *HttpClient) GetResponse() (*http.Response, error)

GetResponse 获取http.response

func (*HttpClient) PostFile added in v0.2.37

func (h *HttpClient) PostFile(formname, filename string) *HttpClient

PostFile add a post file to the request

func (*HttpClient) SetBasicAuth added in v0.2.37

func (h *HttpClient) SetBasicAuth(username string, password string) *HttpClient

SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.

func (*HttpClient) SetBody added in v0.2.37

func (h *HttpClient) SetBody(data any) *HttpClient

SetBody 设置请求Body it supports string and []byte.

func (*HttpClient) SetEnableCookie added in v0.2.37

func (h *HttpClient) SetEnableCookie(enable bool) *HttpClient

SetEnableCookie sets enable/disable cookiejar

func (*HttpClient) SetHeader added in v0.2.37

func (h *HttpClient) SetHeader(key, value string) *HttpClient

SetHeader 设置请求Header

func (*HttpClient) SetHost added in v0.2.37

func (h *HttpClient) SetHost(host string) *HttpClient

SetHost 设置请求Host

func (*HttpClient) SetJsonBody added in v0.2.37

func (h *HttpClient) SetJsonBody(obj any) *HttpClient

SetJsonBody 设置Json格式请求Body

func (*HttpClient) SetParam added in v0.2.37

func (h *HttpClient) SetParam(key, value string) *HttpClient

SetParam 设置请求参数

func (*HttpClient) SetParams added in v0.2.37

func (h *HttpClient) SetParams(params map[string]any) *HttpClient

SetParams 设置键值对格式请求参数

func (*HttpClient) SetProxy added in v0.2.37

func (h *HttpClient) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpClient

SetProxy 设置Http代理

func (*HttpClient) SetRetries added in v0.2.37

func (h *HttpClient) SetRetries(times int) *HttpClient

SetRetries 设置请求失败重试次数 0:不重试(默认) -1:一直重试

func (*HttpClient) SetTimeout added in v0.2.37

func (h *HttpClient) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpClient

SetTimeout 设置超时时间

func (*HttpClient) SetUserAgent added in v0.2.37

func (h *HttpClient) SetUserAgent(useragent string) *HttpClient

SetUserAgent 设置User-Agent

func (*HttpClient) SetXmlBody added in v0.2.37

func (h *HttpClient) SetXmlBody(obj any) *HttpClient

SetXmlBody 设置XML格式请求Body

func (*HttpClient) Settings added in v0.2.37

func (h *HttpClient) Settings(settings HttpSettings) *HttpClient

Settings 设置请求配置

func (*HttpClient) ToBytes added in v0.2.37

func (h *HttpClient) ToBytes() ([]byte, error)

func (*HttpClient) ToFile added in v0.2.37

func (h *HttpClient) ToFile(filename string) error

ToFile saves the body data in response to one file. it calls Response inner.

func (*HttpClient) ToJSON added in v0.2.37

func (h *HttpClient) ToJSON(v any) error

ToJSON 将响应作为json解析

func (*HttpClient) ToString added in v0.2.37

func (h *HttpClient) ToString() (string, error)

ToString 将相应转换成字符串

func (*HttpClient) ToXML added in v0.2.37

func (h *HttpClient) ToXML(v any) error

ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.

type HttpSettings

type HttpSettings struct {
	ShowDebug        bool
	UserAgent        string
	ConnectTimeout   time.Duration
	ReadWriteTimeout time.Duration
	// TLSClientConfig  *tls.Config
	Proxy         func(*http.Request) (*url.URL, error)
	CheckRedirect func(req *http.Request, via []*http.Request) error
	EnableCookie  bool
	Gzip          bool
	DumpBody      bool
	Retries       int // if set to -1 means will retry forever
}

http.Client settings

Jump to

Keyboard shortcuts

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