Documentation ¶
Index ¶
- Variables
- func Do(i interface{}) (*http.Response, error)
- func GetAllBody(raw interface{}) []byte
- func NewHttpNewRequest(method, url string, opts ...http_struct.HttpOption) (*http_struct.YakHttpRequest, error)
- func WithBody(value interface{}) http_struct.HttpOption
- func WithContext(ctx context.Context) http_struct.HttpOption
- func WithCookie(value interface{}) http_struct.HttpOption
- func WithFakeUserAgent() http_struct.HttpOption
- func WithFromPlugin(value string) http_struct.HttpOption
- func WithGetParams(i interface{}) http_struct.HttpOption
- func WithHeader(key, value interface{}) http_struct.HttpOption
- func WithJsonBody(value interface{}) http_struct.HttpOption
- func WithNoRedirect() http_struct.HttpOption
- func WithPostParams(i interface{}) http_struct.HttpOption
- func WithProxy(values ...string) http_struct.HttpOption
- func WithRedirectHandler(c func(r *http.Request, vias []*http.Request) bool) http_struct.HttpOption
- func WithRuntimeID(value string) http_struct.HttpOption
- func WithSave(value bool) http_struct.HttpOption
- func WithSession(value interface{}) http_struct.HttpOption
- func WithSource(value string) http_struct.HttpOption
- func WithTimeout(f float64) http_struct.HttpOption
- func WithUserAgent(value interface{}) http_struct.HttpOption
Constants ¶
This section is empty.
Variables ¶
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": WithUserAgent, "useragent": WithUserAgent, "fakeua": WithFakeUserAgent, "header": WithHeader, "cookie": WithCookie, "body": WithBody, "json": WithJsonBody, "params": WithGetParams, "postparams": WithPostParams, "proxy": WithProxy, "timeout": WithTimeout, "redirect": WithRedirectHandler, "noredirect": WithNoRedirect, "session": WithSession, "source": WithSource, "fromPlugin": WithFromPlugin, "runtimeID": WithRuntimeID, "save": WithSave, "context": WithContext, "uarand": _getuarand, }
Functions ¶
func Do ¶
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 GetAllBody ¶
func GetAllBody(raw interface{}) []byte
GetAllBody 获取响应结构体引用的原始响应报文 Example: ``` rsp, err = http.Get("http://www.yaklang.com") raw = http.GetAllBody(rsp) ```
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 WithBody ¶ added in v1.3.2
func WithBody(value interface{}) http_struct.HttpOption
body 是一个请求选项参数,用于指定请求体 Example: ``` rsp, err = http.Post("https://pie.dev/post", http.body("a=b&c=d")) ```
func WithContext ¶ added in v1.3.2
func WithContext(ctx context.Context) http_struct.HttpOption
context 是一个请求选项参数,用于设置请求的上下文 Example: ``` ctx = context.New() rsp, err = http.Get("http://www.example.com", http.context(ctx)) // 向 example.com 发起请求,使用指定的上下文 ```
func WithCookie ¶ added in v1.3.2
func WithCookie(value interface{}) http_struct.HttpOption
header 是一个请求选项参数,用于设置完整的 Cookie 字段 Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.WithCookie("a=b; c=d")) ```
func WithFakeUserAgent ¶ added in v1.3.2
func WithFakeUserAgent() http_struct.HttpOption
fakeua 是一个请求选项参数,用于随机指定请求的 User-Agent Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.fakeua()) ```
func WithFromPlugin ¶ added in v1.3.2
func WithFromPlugin(value string) http_struct.HttpOption
func WithGetParams ¶ added in v1.3.2
func WithGetParams(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 WithHeader ¶ added in v1.3.2
func WithHeader(key, value interface{}) http_struct.HttpOption
header 是一个请求选项参数,用于添加/指定请求头 Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.header("AAA", "BBB")) ```
func WithJsonBody ¶ added in v1.3.2
func WithJsonBody(value interface{}) http_struct.HttpOption
json 是一个请求选项参数,用于指定 JSON 格式的请求体 它会将传入的值进行 JSON 序列化,然后设置序列化后的值为请求体 Example: ``` rsp, err = http.Post("https://pie.dev/post", http.header("Content-Type", "application/json"), http.json({"a": "b", "c": "d"})) ```
func WithNoRedirect ¶ added in v1.3.2
func WithNoRedirect() http_struct.HttpOption
noredirect 是一个请求选项参数,用于禁止重定向 Example: ``` rsp, err = http.Get("http://pie.dev/redirect/3", http.noredirect()) ```
func WithPostParams ¶ added in v1.3.2
func WithPostParams(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 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")) ```
func WithRedirectHandler ¶ added in v1.3.2
func WithRedirectHandler(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 WithRuntimeID ¶ added in v1.3.2
func WithRuntimeID(value string) http_struct.HttpOption
func WithSave ¶ added in v1.3.2
func WithSave(value bool) http_struct.HttpOption
save 是一个请求选项参数,用于指定是否将此次请求的记录保存在数据库中,默认为true即会保存到数据库 Example: ``` http.Get("https://exmaple.com", http.save(true)) // 向 example.com 发起请求,会将此次请求保存到数据库中 ```
func WithSession ¶ added in v1.3.2
func WithSession(value interface{}) http_struct.HttpOption
session 是一个请求选项参数,用于根据传入的值指定会话,使用相同的值会使用同一个会话,同一个会话会自动复用 Cookie Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.session("request1")) ```
func WithSource ¶ added in v1.3.2
func WithSource(value string) http_struct.HttpOption
source 是一个请求选项参数,用于在请求记录保存到数据库时标识此次请求的来源 Example: ``` rsp, err = http.Get("https://exmaple.com", http.save(true), http.source("test")) // 向 example.com 发起请求,会将此次请求保存到数据库中,指示此次请求的来源为test ```
func WithTimeout ¶ added in v1.3.2
func WithTimeout(f float64) http_struct.HttpOption
WithTimeout 是一个请求选项参数,用于设置请求超时时间,单位是秒 Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.WithTimeout(10)) ```
func WithUserAgent ¶ added in v1.3.2
func WithUserAgent(value interface{}) http_struct.HttpOption
useragent 是一个请求选项参数,用于指定请求的 User-Agent Example: ``` rsp, err = http.Get("http://www.yaklang.com", http.ua("yaklang-http")) ```
Types ¶
This section is empty.