http

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewH2CHTTP

func NewH2CHTTP(timeout int) *Client

NewH2CHTTP 创建新的H2C客户端 NewH2CHTTP return H2C客户端对象

func NewH2CHTTPWithoutRedirect

func NewH2CHTTPWithoutRedirect(timeout int) *Client

NewH2CHTTPWithoutRedirect 创建新的H2C客户端(不自动跟踪301和302跳转) NewH2CHTTPWithoutRedirect return H2C客户端对象

func NewHTTP

func NewHTTP(timeout int) *Client

NewHTTP 创建新的HTTP客户端 * timeout 请求的超时时间,单位(毫秒) NewHTTP return HTTP客户端对象

func NewHTTPWithoutRedirect

func NewHTTPWithoutRedirect(timeout int) *Client

NewHTTPWithoutRedirect 创建新的HTTP客户端(不自动跟踪301和302跳转) * timeout 请求的超时时间,单位(毫秒) NewHTTPWithoutRedirect return HTTP客户端对象

func (*Client) Delete

func (c *Client) Delete(ctx *plugin.Context, url string, body interface{}, headers *map[string]string) (*Result, error)

Delete 发送DELETE请求

func (*Client) Do

func (c *Client) Do(ctx *plugin.Context, method string, url string, body interface{}, headers *map[string]string) (*Result, error)

Do 发送请求 * method 请求方法,GET、POST等

func (*Client) Get

func (c *Client) Get(ctx *plugin.Context, url string, headers *map[string]string) (*Result, error)

Get 发送GET请求 * url 以http://或https://开头的URL地址,如果设置了baseURL可以只提供path部分 * headers 传入一个Key-Value对象的HTTP头信息,如果不指定头信息这个参数可以省略不传 * return 返回结果对象,如果返回值是JSON格式,将自动转化为对象否则将字符串放在.result中,如发生错误将抛出异常,返回的对象中还包括:headers、statusCode、statusMessage

func (*Client) Head

func (c *Client) Head(ctx *plugin.Context, url string, headers *map[string]string) (*Result, error)

Head 发送HEAD请求

func (*Client) ManualDo

func (c *Client) ManualDo(ctx *plugin.Context, method string, url string, body interface{}, headers *map[string]string) (*ManualResult, error)

ManualDo 手动处理请求,需要自行从返回结果中读取数据,可实现SSE客户端 ManualDo return 应答的对象(需手动读取数据并关闭请求)

func (*Client) Open

func (c *Client) Open(ctx *plugin.Context, url string, headers *map[string]string) (*WS, error)

Open 打开一个Websocket连接 Open return Websocket对象(使用完毕请关闭连接)

func (*Client) Post

func (c *Client) Post(ctx *plugin.Context, url string, body interface{}, headers *map[string]string) (*Result, error)

Post 发送POST请求 * body 可以传入任意类型,如果不是字符串或二进制数组时会自动添加application/json头,数据将以json格式发送

func (*Client) Put

func (c *Client) Put(ctx *plugin.Context, url string, body interface{}, headers *map[string]string) (*Result, error)

Put 发送PUT请求

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(url string)

SetBaseURL 设置一个URL前缀,后续请求中可以只提供path部分 SetBaseURL url 以http://或https://开头的URL地址

func (*Client) SetGlobalHeaders

func (c *Client) SetGlobalHeaders(headers map[string]string)

SetGlobalHeaders 设置固定的HTTP头部信息,在每个请求中都加入这些HTTP头 SetGlobalHeaders headers 传入一个Key-Value对象的HTTP头信息

type ManualResult added in v1.0.5

type ManualResult struct {
	Result
	// contains filtered or unexported fields
}

func (*ManualResult) Close added in v1.0.5

func (r *ManualResult) Close() error

func (*ManualResult) Read added in v1.0.5

func (r *ManualResult) Read(n int) (string, error)

func (*ManualResult) ReadBytes added in v1.0.5

func (r *ManualResult) ReadBytes(n int) ([]byte, error)

func (*ManualResult) Save added in v1.0.5

func (r *ManualResult) Save(filename string) error

type Result added in v1.0.5

type Result struct {
	Error      string
	StatusCode int
	Headers    map[string]string
	Data       interface{}
	// contains filtered or unexported fields
}

func (*Result) Bytes added in v1.0.5

func (r *Result) Bytes() []byte

func (*Result) String added in v1.0.5

func (r *Result) String() string

type WS

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

func (*WS) Close

func (ws *WS) Close() error

Close 关闭连接

func (*WS) EnableCompression

func (ws *WS) EnableCompression()

EnableCompression 启用压缩

func (*WS) Read

func (ws *WS) Read() (string, error)

Read 读取文本数据 Read return 读取到的字符串

func (*WS) ReadBytes

func (ws *WS) ReadBytes() ([]byte, error)

ReadBytes 读取二进制数据 ReadBytes return 读取到的二进制数据

func (*WS) ReadJSON

func (ws *WS) ReadJSON() (interface{}, error)

ReadJSON 读取JSON对象 ReadJSON return 读取到的对象

func (*WS) Write

func (ws *WS) Write(content string) error

Write 写入文本数据 Write content 文本数据

func (*WS) WriteBytes

func (ws *WS) WriteBytes(content []byte) error

WriteBytes 写入二进制数据 WriteBytes content 二进制数据

func (*WS) WriteJSON

func (ws *WS) WriteJSON(content interface{}) error

WriteJSON 写入对象 WriteJSON content 对象

Jump to

Keyboard shortcuts

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