requests

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoDisposition    = errors.New("not found content disposition header")
	ErrNotFoundDstField = errors.New("not found dst field")
	ErrNoCookie         = errors.New("not found cookie")
)

Functions

func BatchFileUpload2Internal

func BatchFileUpload2Internal(files []FileUpload) []grequests.FileUpload

BatchFileUpload2Internal 批量转化

func CookieStr2Cookie

func CookieStr2Cookie(cookieStr string) []*http.Cookie

Types

type FileUpload

type FileUpload struct {
	FileName     string        //文件名
	FileContents io.ReadCloser //文件流
	FieldName    string        //上传文件表单 文件字段
	FileMime     string        //文件类型, 默认是application/octet-stream
}

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(req *HTTPRequest) *HTTPClient

func (*HTTPClient) CronClearIdle

func (api *HTTPClient) CronClearIdle(task *routine.Task, interval time.Duration) error

CronClearIdle 定时清理闲置连接

func (*HTTPClient) Delete

func (api *HTTPClient) Delete(url string, rOpts ...ROpt) (*HTTPResponse, error)

Delete DELETE请求方法

func (*HTTPClient) Get

func (api *HTTPClient) Get(url string, rOpts ...ROpt) (*HTTPResponse, error)

Get GET请求方法

func (*HTTPClient) Head

func (api *HTTPClient) Head(url string, rOpts ...ROpt) (*HTTPResponse, error)

Head HEAD请求方法

func (*HTTPClient) Method

func (api *HTTPClient) Method(method string, url string, rOpts ...ROpt) (*HTTPResponse, error)

Method 请求

func (*HTTPClient) Options

func (api *HTTPClient) Options(url string, rOpts ...ROpt) (*HTTPResponse, error)

Options OPTIONS请求方法

func (*HTTPClient) Patch

func (api *HTTPClient) Patch(url string, rOpts ...ROpt) (*HTTPResponse, error)

Patch PATCH请求方法

func (*HTTPClient) Post

func (api *HTTPClient) Post(url string, rOpts ...ROpt) (*HTTPResponse, error)

Post Post请求方法

func (*HTTPClient) Put

func (api *HTTPClient) Put(url string, rOpts ...ROpt) (*HTTPResponse, error)

Put PUT请求方法

type HTTPRequest

type HTTPRequest struct {
	Url       string            //Url
	Header    map[string]string //请求头
	Params    map[string]string //查询字符串
	Form      map[string]string //表单参数
	Json      []byte            //json请求体
	Cookie    []*http.Cookie    //Cookie
	UserAgent string            //UserAgent
	Timeout   time.Duration     //请求超时时间
	Files     []FileUpload      //文件
}

func NewRequest

func NewRequest(args ...ROpt) *HTTPRequest

type HTTPResponse

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

func Delete

func Delete(url string, rOpts ...ROpt) (*HTTPResponse, error)

func Get

func Get(url string, rOpts ...ROpt) (*HTTPResponse, error)
func Head(url string, rOpts ...ROpt) (*HTTPResponse, error)

func NewResponse

func NewResponse(response *grequests.Response) *HTTPResponse

func Options

func Options(url string, rOpts ...ROpt) (*HTTPResponse, error)

func Patch

func Patch(url string, rOpts ...ROpt) (*HTTPResponse, error)

func Post

func Post(url string, rOpts ...ROpt) (*HTTPResponse, error)

func Put

func Put(url string, rOpts ...ROpt) (*HTTPResponse, error)

func (*HTTPResponse) Bytes

func (resp *HTTPResponse) Bytes() []byte

Bytes 字节, 适用于小文件, 大文件推荐使用Stream

func (*HTTPResponse) ContentType

func (resp *HTTPResponse) ContentType() string

ContentType 获取Content-Type

func (*HTTPResponse) Cookie

func (resp *HTTPResponse) Cookie(name string) (*http.Cookie, error)

Cookie 获取Cookie, 没有返回空字符串

func (*HTTPResponse) Cookies

func (resp *HTTPResponse) Cookies() []*http.Cookie

Cookies 获取Cookies, 没有返回空切片

func (*HTTPResponse) Error

func (resp *HTTPResponse) Error() error

Error 错误

func (*HTTPResponse) FileName

func (resp *HTTPResponse) FileName() (string, error)

FileName 文件名

func (*HTTPResponse) FileNameWithCustom

func (resp *HTTPResponse) FileNameWithCustom(nameField string) (string, error)

FileNameWithCustom 文件名

func (*HTTPResponse) Header

func (resp *HTTPResponse) Header(name string) string

Header 返回的Header

func (*HTTPResponse) Headers

func (resp *HTTPResponse) Headers(name string) []string

Headers 返回的Header, 大小写不敏感

func (*HTTPResponse) Json

func (resp *HTTPResponse) Json(dst interface{}) error

Json 请求体序列化结构体

func (*HTTPResponse) OK

func (resp *HTTPResponse) OK() bool

OK 请求是否OK

func (*HTTPResponse) Status

func (resp *HTTPResponse) Status() int

Status 状态码

func (*HTTPResponse) Text

func (resp *HTTPResponse) Text() string

Text 返回的文本内容

type ROpt

type ROpt func(r *HTTPRequest)

func RWithCookie

func RWithCookie(cookie []*http.Cookie) ROpt

func RWithFile

func RWithFile(file FileUpload) ROpt

func RWithFiles

func RWithFiles(files []FileUpload) ROpt

func RWithForm

func RWithForm(form map[string]string) ROpt

func RWithHeader

func RWithHeader(header map[string]string) ROpt

func RWithJson

func RWithJson(body []byte) ROpt

func RWithParams

func RWithParams(params map[string]string) ROpt

func RWithTimeout

func RWithTimeout(timeout time.Duration) ROpt

func RWithUserAgent

func RWithUserAgent(userAgent string) ROpt

Jump to

Keyboard shortcuts

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