libhttp

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 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 HttpRequest

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

func Delete

func Delete(url string) *HttpRequest

Delete

func Get

func Get(url string) *HttpRequest

Get

func Head(url string) *HttpRequest

Head

func NewRequest

func NewRequest(rawUrl, method string) *HttpRequest

func Post

func Post(url string) *HttpRequest

Post

func Put

func Put(url string) *HttpRequest

Put

func (*HttpRequest) AddCookie

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

添加请求Cookie

func (*HttpRequest) AddParam

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

增加请求参数

func (*HttpRequest) GetResponse added in v0.1.6

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

获取http.response

func (*HttpRequest) PostFile

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

PostFile add a post file to the request

func (*HttpRequest) SetBasicAuth

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

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

func (*HttpRequest) SetBody

func (h *HttpRequest) SetBody(data interface{}) *HttpRequest

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

func (*HttpRequest) SetEnableCookie

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

SetEnableCookie sets enable/disable cookiejar

func (*HttpRequest) SetHeader

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

设置请求Header

func (*HttpRequest) SetHost

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

设置请求Host

func (*HttpRequest) SetJsonBody

func (h *HttpRequest) SetJsonBody(obj interface{}) (*HttpRequest, error)

设置Json格式请求Body

func (*HttpRequest) SetParam

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

设置请求参数

func (*HttpRequest) SetParams

func (h *HttpRequest) SetParams(params map[string]interface{}) *HttpRequest

设置键值对格式请求参数

func (*HttpRequest) SetProxy

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

设置Http代理

func (*HttpRequest) SetRetries

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

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

func (*HttpRequest) SetTimeout

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

设置超时时间

func (*HttpRequest) SetUserAgent

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

设置User-Agent

func (*HttpRequest) SetXmlBody

func (h *HttpRequest) SetXmlBody(obj interface{}) (*HttpRequest, error)

设置XML格式请求Body

func (*HttpRequest) Settings

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

设置请求配置

func (*HttpRequest) ToBytes

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

func (*HttpRequest) ToFile

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

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

func (*HttpRequest) ToJSON

func (h *HttpRequest) ToJSON(v interface{}) error

将响应作为json解析

func (*HttpRequest) ToString

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

将相应转换成字符串

func (*HttpRequest) ToXML

func (h *HttpRequest) ToXML(v interface{}) 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