yakhttp

package
v1.3.1-sp1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HttpExports = map[string]interface{}{

	"Raw": rawRequest,

	"Get":     _get,
	"Post":    _post,
	"Request": httpRequest,

	"Do":         Do,
	"NewRequest": NewHttpNewRequest,

	"GetAllBody": GetAllBody,

	"dump":     dump,
	"show":     httpShow,
	"dumphead": dumphead,
	"showhead": showhead,

	"ua":        UserAgent,
	"useragent": UserAgent,
	"fakeua":    FakeUserAgent,

	"header": Header,

	"cookie": Cookie,

	"body": Body,

	"json": JsonBody,

	"params":     GetParams,
	"postparams": PostParams,

	"proxy": WithProxy,

	"timeout": timeout,

	"redirect":   RedirectHandler,
	"noredirect": NoRedirect,

	"session": Session,

	"uarand": _getuarand,
}

Functions

func Body

func Body(value interface{}) http_struct.HttpOption

body 是一个请求选项参数,用于指定请求体 Example: ``` rsp, err = http.Post("https://pie.dev/post", http.body("a=b&c=d")) ```

func Cookie(value interface{}) http_struct.HttpOption

header 是一个请求选项参数,用于设置 Cookie Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.Cookie("a=b; c=d")) ```

func Do

func Do(i interface{}) (*http.Response, error)

Do 根据构造好的请求结构体引用发送请求,返回响应结构体引用与错误 ! 已弃用 Example: ``` req, err = http.Raw("GET / HTTP/1.1\r\nHost: www.yaklang.com\r\n\r\n") rsp, err = http.Do(req) ```

func FakeUserAgent

func FakeUserAgent() http_struct.HttpOption

fakeua 是一个请求选项参数,用于随机指定请求的 User-Agent Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.fakeua()) ```

func GetAllBody

func GetAllBody(raw interface{}) []byte

GetAllBody 获取响应结构体引用的原始响应报文 Example: ``` rsp, err = http.Get("http://www.yaklang.com") raw = http.GetAllBody(rsp) ```

func GetParams

func GetParams(i interface{}) http_struct.HttpOption

params 是一个请求选项参数,用于添加/指定 GET 参数,这会将参数进行 URL 编码 Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.params("a=b"), http.params("c=d")) ```

func Header(key, value interface{}) http_struct.HttpOption

header 是一个请求选项参数,用于添加/指定请求头 Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.header("AAA", "BBB")) ```

func JsonBody

func JsonBody(value interface{}) http_struct.HttpOption

body 是一个请求选项参数,用于指定 JSON 格式的请求体 它会将传入的值进行 JSON 序列化,然后设置序列化后的值为请求体 Example: ``` rsp, err = http.Post("https://pie.dev/post", http.header("Content-Type", "application/json"), http.json({"a": "b", "c": "d"})) ```

func NewHttpNewRequest

func NewHttpNewRequest(method, url string, opts ...http_struct.HttpOption) (*http_struct.YakHttpRequest, error)

NewRequest 根据指定的 method 和 URL 生成请求结构体引用,返回请求结构体引用与错误,它的第一个参数是 URL ,接下来可以接收零个到多个请求选项,用于对此次请求进行配置,例如设置超时时间等 注意,此函数只会生成请求结构体引用,不会发起请求 ! 已弃用 Example: ``` req, err = http.NewRequest("GET", "http://www.yaklang.com", http.timeout(10)) ```

func NoRedirect

func NoRedirect() http_struct.HttpOption

noredirect 是一个请求选项参数,用于禁止重定向 Example: ``` rsp, err = http.Get("http://pie.dev/redirect/3", http.noredirect()) ```

func PostParams

func PostParams(i interface{}) http_struct.HttpOption

postparams 是一个请求选项参数,用于添加/指定 POST 参数,这会将参数进行 URL 编码 Example: ``` rsp, err = http.Post("http://www.yaklang.com", http.postparams("a=b"), http.postparams("c=d")) ```

func RedirectHandler

func RedirectHandler(c func(r *http.Request, vias []*http.Request) bool) http_struct.HttpOption

redirect 是一个请求选项参数,它接收重定向处理函数,用于自定义重定向处理逻辑,返回 true 代表继续重定向,返回 false 代表终止重定向 重定向处理函数中第一个参数是当前的请求结构体引用,第二个参数是之前的请求结构体引用 Example: ``` rsp, err = http.Get("http://pie.dev/redirect/3", http.redirect(func(r, vias) bool { return true }) ```

func Session

func Session(value interface{}) http_struct.HttpOption

session 是一个请求选项参数,用于根据传入的值指定会话,使用相同的值会使用同一个会话,同一个会话会自动复用 Cookie Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.session("request1")) ```

func UserAgent

func UserAgent(value interface{}) http_struct.HttpOption

useragent 是一个请求选项参数,用于指定请求的 User-Agent Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.ua("yaklang-http")) ```

func WithProxy added in v1.3.1

func WithProxy(values ...string) http_struct.HttpOption

proxy 是一个请求选项参数,用于设置一个或多个请求的代理,请求时会根据顺序找到一个可用的代理使用 Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.proxy("http://127.0.0.1:7890", "http://127.0.0.1:8083")) ```

Types

This section is empty.

Jump to

Keyboard shortcuts

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