request

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentType               = "Content-Type"
	ApplicationJSON           = "application/json"
	ApplicationFormUrlencoded = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func AddRequestInterceptors

func AddRequestInterceptors(interceptors ...RequestInterceptor)

AddRequestInterceptors 添加请求拦截器

Types

type Client

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

Client 封装了http的参数等信息

func Delete

func Delete(url string) *Client

Delete http `DELETE` 请求

func Get

func Get(url string) *Client

Get http `GET` 请求

func Post

func Post(url string) *Client

Post http `POST` 请求

func Put

func Put(url string) *Client

Put http `PUT` 请求

func Request

func Request(url, method string, client *http.Client) *Client

Request 用于自定义请求方式,比如`HEAD`、`PATCH`、`OPTIONS`、`TRACE` client参数用于替换DefaultClient,如果为nil则会使用默认的

func (*Client) Form

func (c *Client) Form(form url.Values) *Client

Form 表单提交参数

func (*Client) Header

func (c *Client) Header(k, v string) *Client

Header http请求头

func (*Client) Headers

func (c *Client) Headers(header http.Header) *Client

Headers http请求头

func (*Client) Json

func (c *Client) Json(json interface{}) *Client

Json json提交参数 如果是string,则默认当作是json字符串;否则会序列化为json字节数组,再发送

func (*Client) Multipart

func (c *Client) Multipart(multipart FileForm) *Client

Multipart form-data提交参数

func (*Client) Params

func (c *Client) Params(params url.Values) *Client

Params http请求中url参数

func (*Client) Send

func (c *Client) Send() *Result

Send 发送http请求

type FileForm

type FileForm struct {
	Value url.Values
	File  map[string]string
}

FileForm form参数和文件参数

type RequestInterceptor

type RequestInterceptor func(request *http.Request) error

RequestInterceptor 请求拦截器 返回不为nil,即有错误会终止后续执行

type Result

type Result struct {
	Resp *http.Response
	Err  error
}

Result http响应结果

func (*Result) Json

func (r *Result) Json(v interface{}) error

Json 获取http响应内容,返回json

func (*Result) Raw

func (r *Result) Raw() ([]byte, error)

Raw 获取http响应内容,返回字节数组

func (*Result) Save

func (r *Result) Save(name string) error

Save 获取http响应内容,保存为文件

func (*Result) Status2xx

func (r *Result) Status2xx() *Result

Status2xx 判断http响应码是否为2xx

func (*Result) StatusOk

func (r *Result) StatusOk() *Result

StatusOk 判断http响应码是否为200

func (*Result) Text

func (r *Result) Text() (string, error)

Text 获取http响应内容,返回字符串

Jump to

Keyboard shortcuts

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