requests

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MulanPSL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CUrlencoded  = "application/x-www-form-urlencoded"
	CJson        = "application/json"
	CFormData    = "application/form-data"
	MethodGet    = "GET"
	MethodPost   = "POST"
	MethodPut    = "PUT"
	MethodDelete = "DELETE"
)

Variables

This section is empty.

Functions

func FormatUrlValues

func FormatUrlValues(b map[string]any) url.Values

FormatUrlValues map to CUrlencoded 数据

Types

type Response

type Response struct {
	Status     string // e.g. "200 OK"
	StatusCode int    // e.g. 200

	// Header 将标头键映射到值。如果响应具有具有相同键的多个标头,则可以使用逗号分隔符将它们连接起来。
	//(RFC 7230 第 3.2.2 节要求多个标头在语义上等效于逗号分隔的序列。
	// 当标头值被此结构中的其他字段(例如,ContentLength、TransferEncoding、Trailer)复制时,字段值是权威的。
	//
	// 映射中的键是规范化的(请参阅 CanonicalHeaderKey)
	Header http.Header

	Body []byte

	Cookies []*http.Cookie
}

Response 请求结果

func Get

func Get(url string, params any, header map[string]string, proxy string, cookies any) (*Response, error)

Get 会话请求 cookies 可选 string / map[string]string

func Post

func Post(url string, _data, _json any, header map[string]string, proxy string, cookies any) (*Response, error)

Post 会话请求 cookies 可选 string / map[string]string

type Session

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

Session http.client 简单功能封装

func NewSession

func NewSession(defaultHeader map[string]string) *Session

NewSession 创建 Session 对象。可以自定义请求头

func (*Session) Do

func (s *Session) Do(method, url string, params, _data, _json any) (*Response, error)

Do 发送请求

method:	请求方法 MethodGet , MethodPost , MethodPut , MethodDelete
params: GET请求参数,可选 字符串(string)/ 键值对(map[string]any)/ nil 例:a=5&b=6&c="acc" / map[string]any{ "a":5, "b":6, "c":"acc" }
data:	用于提交 x-www-form-urlencoded 数据, 可选 string / []byte / map[string]any / io.Reader / nil
_json:	用于提交 json 数据, 可选 string / []byte / map[string]any / io.Reader / nil

func (*Session) Get

func (s *Session) Get(url string, params any) (*Response, error)

Get 会话请求

params: GET请求参数,可选 字符串(string)/ 键值对(map[string]any)/ nil

func (*Session) Post

func (s *Session) Post(url string, _data, _json any) (*Response, error)

Post 会话请求

data:	用于提交 x-www-form-urlencoded 数据, 可选 string / []byte / map[string]any / io.Reader / nil
_json:	用于提交 json 数据, 可选 string / []byte / map[string]any / io.Reader / nil

func (*Session) Proxy

func (s *Session) Proxy(proxy string)

Proxy 设置代理,例:http://127.0.0.1:8888

Jump to

Keyboard shortcuts

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