httpc

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: MIT Imports: 13 Imported by: 1

README

httpc

http client

Documentation

Index

Constants

View Source
const (
	HTTPHeaderAccept             = "Accept"
	HTTPHeaderAcceptEncoding     = "Accept-Encoding"
	HTTPHeaderAuthorization      = "Authorization"
	HTTPHeaderCacheControl       = "Cache-Control"
	HTTPHeaderContentDisposition = "Content-Disposition"
	HTTPHeaderContentEncoding    = "Content-Encoding"
	HTTPHeaderContentLength      = "Content-Length"
	HTTPHeaderContentMD5         = "Content-MD5"
	HTTPHeaderContentType        = "Content-Type"
	HTTPHeaderContentLanguage    = "Content-Language"
	HTTPHeaderDate               = "Date"
	HTTPHeaderEtag               = "ETag"
	HTTPHeaderExpires            = "Expires"
	HTTPHeaderHost               = "Host"
	HTTPHeaderLastModified       = "Last-Modified"
	HTTPHeaderRange              = "Range"
	HTTPHeaderLocation           = "Location"
	HTTPHeaderOrigin             = "Origin"
	HTTPHeaderServer             = "Server"
	HTTPHeaderUserAgent          = "User-Agent"
	HTTPHeaderIfModifiedSince    = "If-Modified-Since"
	HTTPHeaderIfUnmodifiedSince  = "If-Unmodified-Since"
	HTTPHeaderIfMatch            = "If-Match"
	HTTPHeaderIfNoneMatch        = "If-None-Match"
	HTTPHeaderProxyAuthorization = "Proxy-Authorization"
)

Http Header name

View Source
const (
	ContentTypeForm = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func CreateTransport

func CreateTransport(timeout *Timeout, keepAlive bool) (ret *http.Transport)

CreateTransport 创建Transport, timeout可以为nil,使用proxySetting

func SetProxy

func SetProxy(p *Proxy)

Types

type Client

type Client struct {
	Header  http.Header
	Timeout *Timeout
	Ctx     context.Context
}

http客户端

func (*Client) Get

func (p *Client) Get(url string) (*http.Response, error)

需要执行res.Body.Close()来关闭body

func (*Client) GetBytes

func (p *Client) GetBytes(url string) ([]byte, error)

func (*Client) GetJSON

func (p *Client) GetJSON(url string, v interface{}) error

func (*Client) GetXML

func (p *Client) GetXML(url string, v interface{}) error

func (*Client) Post

func (p *Client) Post(url string, body io.Reader) (*http.Response, error)

func (*Client) PostBytes

func (p *Client) PostBytes(url string, body []byte) ([]byte, error)

func (*Client) PostForm

func (p *Client) PostForm(url string, data url.Values) (*http.Response, error)

PostForm ContentType is not included in header. It is added auto.

func (*Client) PostFormBytes

func (p *Client) PostFormBytes(url string, data url.Values) ([]byte, error)

func (*Client) PostFormJSON

func (p *Client) PostFormJSON(url string, data url.Values, v interface{}) error

func (*Client) PostFormXML

func (p *Client) PostFormXML(url string, data url.Values, v interface{}) error

func (*Client) PostJSON

func (p *Client) PostJSON(url string, body interface{}, v interface{}) error

func (*Client) PostNone

func (p *Client) PostNone(url string, body io.Reader) error

func (*Client) PostXML

func (p *Client) PostXML(url string, body interface{}, v interface{}) error

func (*Client) Put

func (p *Client) Put(url string, body io.Reader) (*http.Response, error)

需要执行res.Body.Close()来关闭body

func (*Client) PutBytes

func (p *Client) PutBytes(url string, body []byte) ([]byte, error)

func (*Client) PutForm

func (p *Client) PutForm(url string, data url.Values) (*http.Response, error)

PutForm ContentType is not included in header. It is added auto.

func (*Client) PutFormBytes

func (p *Client) PutFormBytes(url string, data url.Values) ([]byte, error)

func (*Client) PutFormJSON

func (p *Client) PutFormJSON(url string, data url.Values, v interface{}) error

func (*Client) PutFormXML

func (p *Client) PutFormXML(url string, data url.Values, v interface{}) error

func (*Client) PutJSON

func (p *Client) PutJSON(url string, body interface{}, v interface{}) error

func (*Client) PutNone

func (p *Client) PutNone(url string, body io.Reader) error

不检查返回值.

func (*Client) PutXML

func (p *Client) PutXML(url string, body interface{}, v interface{}) error

func (*Client) Request

func (p *Client) Request(method, url string, body io.Reader) (*http.Response, error)

Request request a http command.

func (*Client) RequestBytes

func (p *Client) RequestBytes(method, url string, body []byte) ([]byte, error)

func (*Client) RequestForm

func (p *Client) RequestForm(method, url string, data url.Values) (*http.Response, error)

func (*Client) RequestFormBytes

func (p *Client) RequestFormBytes(method, url string, data url.Values) ([]byte, error)

func (*Client) RequestFormJSON

func (p *Client) RequestFormJSON(method, url string, data url.Values, v interface{}) error

func (*Client) RequestFormXML

func (p *Client) RequestFormXML(method, url string, data url.Values, v interface{}) error

func (*Client) RequestJSON

func (p *Client) RequestJSON(method, url string, body interface{}, v interface{}) error

func (*Client) RequestNone

func (p *Client) RequestNone(method, url string, body io.Reader) error

仅执行,不检查响应数据.

func (*Client) RequestXML

func (p *Client) RequestXML(method, url string, body interface{}, v interface{}) error

type Proxy

type Proxy struct {
	Host     string //host name
	User     string //user name for auth. default is "" which means that doesn't use.
	Password string //password for auth.
}

Proxy setting

type Timeout

type Timeout struct {
	Connect time.Duration //connection timeout
	Read    time.Duration //read timeout
	Write   time.Duration //write timeout
	Header  time.Duration //timeout for waiting Response Header
	Idle    time.Duration //timeout for idle
}

Timeout timeout setting. Default is 0 which means that doesn't use and use golang default setting.

Jump to

Keyboard shortcuts

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