http

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadResponse

func ReadResponse(resp *orig.Response, err error) (code int, body []byte)

读取Response的状态码和文本内容

Types

type Client

type Client struct {
	Prefix  string
	Headers map[string]string
	*orig.Client
}

http或https客户端

func NewClient

func NewClient(prefix string) *Client

func (*Client) AddHeader

func (c *Client) AddHeader(key, value string)

func (*Client) Delete

func (c *Client) Delete(url, query string) (int, string)

DELETE操作

func (*Client) Do

func (c *Client) Do(method, url string, reader io.Reader) (int, []byte)

通用操作

func (*Client) DoWrap

func (c *Client) DoWrap(url string, req *Resource, dec DecodeFunc) (int, error)

封装IO

func (*Client) Get

func (c *Client) Get(url, query string) (code int, body string)

GET操作

func (*Client) Head

func (c *Client) Head(url, query string) (int, string)

HEAD操作

func (*Client) Post

func (c *Client) Post(url string, data []byte) (int, []byte)

POST操作

func (*Client) PostForm

func (c *Client) PostForm(url, data string) (int, string)

提交表单

func (*Client) PostJson

func (c *Client) PostJson(url string, obj, res interface{}) (int, error)

提交JSON数据

func (*Client) Put

func (c *Client) Put(url string, data []byte) (int, []byte)

PUT操作

func (*Client) SetContentType

func (c *Client) SetContentType(ctype string)

func (*Client) SetPemCert

func (c *Client) SetPemCert(pemfile string) error

为https设置客户端证书

type DecodeFunc

type DecodeFunc func(body []byte) error

func NewJsonDecoder

func NewJsonDecoder(res interface{}) DecodeFunc

type Resource

type Resource struct {
	HttpMethod  string
	ContentType string
	MimeType    string
	Data        interface{}
}

func NewJsonReq

func NewJsonReq(method, mime string, obj interface{}) *Resource

func NewUpload

func NewUpload(filename string) *Resource

func (*Resource) GetMethod

func (r *Resource) GetMethod() (string, string)

func (*Resource) GetReader

func (r *Resource) GetReader() io.Reader

Jump to

Keyboard shortcuts

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