curl

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAccept        = "Accept"
	HeaderAuthorization = "Authorization"
	HeaderContentType   = "Content-Type"
)
View Source
const (
	ContentText          = "text/plain;charset=utf-8"
	ContentJSON          = "application/json;charset=utf-8"
	ContentForm          = "application/x-www-form-urlencoded"
	ContentStream        = "application/octet-stream"
	ContentFormMultipart = "multipart/form-data"
)
View Source
const MaxFormMemory = 32 << 20

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, method, reqURL string, body []byte, options ...Option) (*http.Response, error)

Do 发送HTTP请求

func Get

func Get(ctx context.Context, reqURL string, options ...Option) (*http.Response, error)

Get 发送GET请求

func Post

func Post(ctx context.Context, reqURL string, body []byte, options ...Option) (*http.Response, error)

Post 发送POST请求

func PostForm

func PostForm(ctx context.Context, reqURL string, data url.Values, options ...Option) (*http.Response, error)

PostForm 发送POST表单请求

func PostJSON

func PostJSON(ctx context.Context, reqURL string, body []byte, options ...Option) (*http.Response, error)

PostJSON 发送POST请求(json数据)

func Upload

func Upload(ctx context.Context, reqURL string, form UploadForm, options ...Option) (*http.Response, error)

Upload 文件上传

Types

type Client

type Client interface {
	// Do 发送HTTP请求
	// 注意:应该使用Context设置请求超时时间
	Do(ctx context.Context, method, reqURL string, body []byte, opts ...Option) (*http.Response, error)
	// Upload 上传文件
	// 注意:应该使用Context设置请求超时时间
	Upload(ctx context.Context, reqURL string, form UploadForm, opts ...Option) (*http.Response, error)
}

Client HTTP客户端

func NewDefaultClient

func NewDefaultClient(certs ...tls.Certificate) Client

NewDefaultClient 生成一个默认的HTTP客户端

func NewHTTPClient

func NewHTTPClient(c *http.Client) Client

NewHTTPClient 通过官方 `http.Client` 生成一个HTTP客户端

type FormFileFunc

type FormFileFunc func(w io.Writer) error

FormFileFunc 将文件写入表单流

type Option

type Option func(o *options)

Option HTTP请求选项

func WithClose

func WithClose() Option

WithClose 请求结束后关闭请求

func WithCookies

func WithCookies(cookies ...*http.Cookie) Option

WithCookies 设置HTTP请求Cookie

func WithHeader

func WithHeader(key string, vals ...string) Option

WithHeader 设置HTTP请求头

type UploadField

type UploadField func(form *uploadform)

UploadField 文件上传表单字段

func WithFormField

func WithFormField(name, value string) UploadField

WithFormField 设置表单普通字段

func WithFormFile

func WithFormFile(fieldname, filename string, fn FormFileFunc) UploadField

WithFormFile 设置表单文件字段

type UploadForm

type UploadForm interface {
	// Field 返回表单普通字段
	Field(name string) string
	// Write 将表单文件写入流
	Write(w *multipart.Writer) error
}

UploadForm HTTP文件上传表单

func NewUploadForm

func NewUploadForm(fields ...UploadField) UploadForm

NewUploadForm 生成一个文件上传表单

Jump to

Keyboard shortcuts

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