requests

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 13 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")
)
View Source
var RequestError = errors.New("RequestError")

Functions

This section is empty.

Types

type FileUpload

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

type HOpt added in v1.2.0

type HOpt func(client *HTTPClient)

func HWithLogger added in v1.4.13

func HWithLogger(logger log.Logger) HOpt

func HWithMaxRetry added in v1.2.1

func HWithMaxRetry(maxTries int) HOpt

func HWithRetryWaitTime added in v1.4.13

func HWithRetryWaitTime(t time.Duration) HOpt

func HWithTimeout added in v1.4.13

func HWithTimeout(timeout time.Duration) HOpt

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(hOPts ...HOpt) *HTTPClient

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) 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 {
	Header        map[string]string // 请求头
	Params        map[string]string // 查询字符串
	Form          map[string]string // 表单参数
	Json          []byte            // json请求体
	Cookie        []*http.Cookie    // Cookie
	UserAgent     string            // UserAgent
	Files         []*FileUpload     // 文件
	Context       context.Context   // 上下文
	Timeout       time.Duration     // 超市时间
	Retries       int               // 重试次数
	RetryWaitTime time.Duration     // 重试等待时间
}

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 *resty.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) 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) 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) Json

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

Json 请求体序列化结构体.

func (*HTTPResponse) OK

func (resp *HTTPResponse) OK() bool

OK 状态码是否在200~300之间.

func (*HTTPResponse) StatusCode added in v1.4.13

func (resp *HTTPResponse) StatusCode() int

StatusCode 状态码.

func (*HTTPResponse) Text

func (resp *HTTPResponse) Text() string

Text 返回的文本内容.

type ROpt

type ROpt func(r *HTTPRequest)

func RWithContext

func RWithContext(ctx context.Context) ROpt

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 RWithRetryWaitTime added in v1.4.13

func RWithRetryWaitTime(t time.Duration) ROpt

func RWithTimeout

func RWithTimeout(timeout time.Duration) ROpt

func RWithTries added in v1.4.13

func RWithTries(retries int) 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