curl

package
v0.0.0-...-784d6ec Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRequestTimeout = errors.New("do request time out")
View Source
var ErrStopRedirect = errors.New("no redirects allowed")

Functions

This section is empty.

Types

type Curl

type Curl struct {
	Url, Method, Cookie, Referer string

	Headers map[string]string
	Options map[string]bool

	RedirectCount int

	//[]byte格式
	PostBytes []byte
	//string格式
	PostString string
	//key=>value格式
	PostFields       neturl.Values
	PostFieldReaders map[string]io.Reader
	//文件,key是字段名,val是文件路径
	PostFiles neturl.Values
	//流
	PostReader io.Reader
	// contains filtered or unexported fields
}

func NewCurl

func NewCurl(url string) *Curl

func (*Curl) CreateRequest

func (curls *Curl) CreateRequest() (httpRequest *http.Request, err error)

func (*Curl) Request

func (curls *Curl) Request(ctxs ...context.Context) (rs *Response, err error)

Request 参数不需要传,请使用SetContext

func (*Curl) SetContext

func (curls *Curl) SetContext(ctx context.Context)

func (*Curl) SetHeader

func (curls *Curl) SetHeader(key, val string)

func (*Curl) SetHeaders

func (curls *Curl) SetHeaders(headers map[string]string)

func (*Curl) SetMethod

func (curls *Curl) SetMethod(method string) error

func (*Curl) SetOption

func (curls *Curl) SetOption(key string, val bool)

func (*Curl) SetOptions

func (curls *Curl) SetOptions(options map[string]bool)

func (*Curl) SetStream

func (curls *Curl) SetStream()

func (*Curl) SetTimeout

func (curls *Curl) SetTimeout(t int)

func (*Curl) SetTimeoutMS

func (curls *Curl) SetTimeoutMS(t int)

毫秒

type Response

type Response struct {
	Headers    map[string]string `json:"headers"`
	Cookie     string            `json:"cookie"`
	Url        string            `json:"url"`
	FollowUrls []string          `json:"follow_urls"`
	Body       []byte            `json:"body"`
	BodyReader io.ReadCloser     `json:"-"`
	// contains filtered or unexported fields
}

func (*Response) Close

func (resp *Response) Close()

func (*Response) ReadBody

func (resp *Response) ReadBody() (body []byte, err error)

Jump to

Keyboard shortcuts

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