gorequest

package
v1.0.188 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIp

func ClientIp(r *http.Request) string

ClientIp 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func DeCode added in v1.0.47

func DeCode(s string) string

DeCode 解码

func GetParamsString added in v1.0.47

func GetParamsString(src interface{}) string

GetParamsString 获取参数字符串

func GetRandomUserAgent

func GetRandomUserAgent() string

GetRandomUserAgent 获取随机UA

func GetRandomUserAgentSystem added in v1.0.47

func GetRandomUserAgentSystem() string

GetRandomUserAgentSystem 获取系统随机UA

func IsWechatMiniProgramRequest added in v1.0.113

func IsWechatMiniProgramRequest(ginCtx *gin.Context, appid string) error

func LenCode added in v1.0.47

func LenCode(s string) string

LenCode 编码

func ParseQuery added in v1.0.47

func ParseQuery(s string) map[string][]string

ParseQuery 获取URL参数 https://studygolang.com/articles/2876

func ToXml added in v1.0.183

func ToXml(params map[string]interface{}) (reader io.Reader, err error)

Types

type App added in v1.0.47

type App struct {
	Uri   string // 全局请求地址,没有设置url才会使用
	Error error  // 错误
	// contains filtered or unexported fields
}

App 实例

func NewHttp added in v1.0.47

func NewHttp() *App

NewHttp 实例化

func (*App) Get added in v1.0.47

func (app *App) Get(ctx context.Context, uri ...string) (httpResponse Response, err error)

Get 发起GET请求

func (*App) Post added in v1.0.47

func (app *App) Post(ctx context.Context, uri ...string) (httpResponse Response, err error)

Post 发起POST请求

func (*App) Request added in v1.0.47

func (app *App) Request(ctx context.Context) (httpResponse Response, err error)

Request 发起请求

func (*App) SetAuthToken added in v1.0.47

func (app *App) SetAuthToken(token string)

SetAuthToken 设置身份验证令牌

func (*App) SetContentTypeForm added in v1.0.47

func (app *App) SetContentTypeForm()

SetContentTypeForm 设置FORM格式

func (*App) SetContentTypeJson added in v1.0.47

func (app *App) SetContentTypeJson()

SetContentTypeJson 设置JSON格式

func (*App) SetContentTypeXml added in v1.0.47

func (app *App) SetContentTypeXml()

SetContentTypeXml 设置XML格式

func (*App) SetCookie added in v1.0.94

func (app *App) SetCookie(value string)

SetCookie 设置Cookie

func (*App) SetDebug added in v1.0.47

func (app *App) SetDebug()

SetDebug 设置调试模式

func (*App) SetHeader added in v1.0.47

func (app *App) SetHeader(key, value string)

SetHeader 设置请求头

func (*App) SetHeaders added in v1.0.47

func (app *App) SetHeaders(headers Headers)

SetHeaders 批量设置请求头

func (*App) SetMethod added in v1.0.47

func (app *App) SetMethod(method string)

SetMethod 设置请求方式

func (*App) SetP12Cert added in v1.0.47

func (app *App) SetP12Cert(content *tls.Certificate)

SetP12Cert 设置证书

func (*App) SetParam added in v1.0.47

func (app *App) SetParam(key string, value interface{})

SetParam 设置请求参数

func (*App) SetParams added in v1.0.47

func (app *App) SetParams(params Params)

SetParams 批量设置请求参数

func (*App) SetTlsVersion added in v1.0.101

func (app *App) SetTlsVersion(minVersion, maxVersion uint16)

SetTlsVersion 设置TLS版本

func (*App) SetUri added in v1.0.47

func (app *App) SetUri(uri string)

SetUri 设置请求地址

func (*App) SetUserAgent added in v1.0.47

func (app *App) SetUserAgent(ua string)

SetUserAgent 设置用户代理,空字符串就随机设置

type Headers added in v1.0.47

type Headers map[string]string

Headers 头部信息

func NewHeaders added in v1.0.47

func NewHeaders() Headers

NewHeaders 新建头部信息

func NewNewHeadersWith added in v1.0.47

func NewNewHeadersWith(headers ...Headers) Headers

NewNewHeadersWith 头部信息使用

func (*Headers) DeepCopy added in v1.0.47

func (h *Headers) DeepCopy() map[string]string

DeepCopy 深度复制

func (Headers) GetQuery added in v1.0.47

func (h Headers) GetQuery() string

GetQuery 获取头部信息

func (Headers) Set added in v1.0.47

func (h Headers) Set(key, value string)

Set 设置头部信息

func (Headers) SetHeaders added in v1.0.47

func (h Headers) SetHeaders(headers Headers)

SetHeaders 批量设置头部信息

type Params added in v1.0.47

type Params map[string]interface{}

Params 参数

func NewParams added in v1.0.47

func NewParams() Params

NewParams 新建参数

func NewParamsWith added in v1.0.47

func NewParamsWith(params ...Params) Params

NewParamsWith 参数使用

func (*Params) DeepCopy added in v1.0.47

func (p *Params) DeepCopy() map[string]interface{}

DeepCopy 深度复制

func (Params) Get added in v1.0.135

func (p Params) Get(key string) interface{}

Get 获取参数

func (Params) Set added in v1.0.47

func (p Params) Set(key string, value interface{})

Set 设置参数

func (Params) SetParams added in v1.0.47

func (p Params) SetParams(params Params)

SetParams 批量设置参数

type Response added in v1.0.47

type Response struct {
	RequestId             string      //【请求】编号
	RequestUri            string      //【请求】链接
	RequestParams         Params      //【请求】参数
	RequestMethod         string      //【请求】方式
	RequestHeader         Headers     //【请求】头部
	RequestCookie         string      //【请求】Cookie
	RequestTime           time.Time   //【请求】时间
	ResponseHeader        http.Header //【返回】头部
	ResponseStatus        string      //【返回】状态
	ResponseStatusCode    int         //【返回】状态码
	ResponseBody          []byte      //【返回】内容
	ResponseContentLength int64       //【返回】大小
	ResponseTime          time.Time   //【返回】时间
}

Response 返回内容

func (*Response) HeaderHtml added in v1.0.52

func (r *Response) HeaderHtml() bool

HeaderHtml 判断是否为Html

func (*Response) HeaderIsImg added in v1.0.52

func (r *Response) HeaderIsImg() bool

HeaderIsImg 判断是否为图片

func (*Response) HeaderIsJpeg added in v1.0.52

func (r *Response) HeaderIsJpeg() bool

HeaderIsJpeg 判断是否为jpeg图片

func (*Response) HeaderIsJpg added in v1.0.52

func (r *Response) HeaderIsJpg() bool

HeaderIsJpg 判断是否为Jpg图片

func (*Response) HeaderIsPng added in v1.0.52

func (r *Response) HeaderIsPng() bool

HeaderIsPng 判断是否为Png图片

func (*Response) HeaderJson added in v1.0.52

func (r *Response) HeaderJson() bool

HeaderJson 判断是否为Json数据

func (*Response) HeaderTextHtml added in v1.0.52

func (r *Response) HeaderTextHtml() bool

HeaderTextHtml 判断是否为Html

func (*Response) HeaderXHtml added in v1.0.52

func (r *Response) HeaderXHtml() bool

HeaderXHtml 判断是否为Html

type ResponseUrlParse added in v1.0.47

type ResponseUrlParse struct {
	Uri      string `json:"uri"`       // URI
	Urn      string `json:"urn"`       // URN
	Url      string `json:"url"`       // URL
	Scheme   string `json:"scheme"`    // 协议
	Host     string `json:"host"`      // 主机
	Hostname string `json:"hostname"`  // 主机名
	Port     string `json:"port"`      // 端口
	Path     string `json:"path"`      // 路径
	RawQuery string `json:"raw_query"` // 参数 ?
	Fragment string `json:"fragment"`  // 片段 #
}

ResponseUrlParse 返回参数

type UriParse added in v1.0.47

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

func NewUri added in v1.0.52

func NewUri(uri string) *UriParse

func (*UriParse) Parse added in v1.0.52

func (u *UriParse) Parse() (resp ResponseUrlParse)

Parse 解析URl

func (*UriParse) UriFilterExcludeQueryString added in v1.0.52

func (u *UriParse) UriFilterExcludeQueryString(uri string) string

UriFilterExcludeQueryString 过滤掉url中的参数

Jump to

Keyboard shortcuts

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