Documentation ¶
Index ¶
- Constants
- func EasyCookie(simple map[string]string) []*http.Cookie
- func EasyGet(strUrl string, values map[string]string) string
- func EasyPost(values map[string]string) url.Values
- func EasyPostFromRequest(r *http.Request)
- func EasyPostJsonRequest(r *http.Request)
- func EasyPostXmlRequest(r *http.Request)
- type BuildResponse
- type CheckRedirect
- type Client
- func (c *Client) AddCookies(cookies []*http.Cookie)
- func (c *Client) AddHeader(header map[string]string)
- func (c *Client) Cookies(cookies []*http.Cookie) *Client
- func (c *Client) DoRequest(r *http.Request) (*http.Response, error)
- func (c *Client) Get(url string) IResponse
- func (c *Client) GetAsyn(url string, call func(response IResponse)) error
- func (c *Client) GetAsynWithCallback(url string, call ICallBack) error
- func (c *Client) Header(header map[string]string) *Client
- func (c *Client) PostBytes(url string, value []byte, req func(request *http.Request)) IResponse
- func (c *Client) PostBytesAsyn(url string, value []byte, req func(request *http.Request), ...) error
- func (c *Client) PostForm(url string, values url.Values) IResponse
- func (c *Client) PostFormAsyn(url string, values url.Values, call func(response IResponse)) error
- func (c *Client) PostFormAsynWithCallback(url string, values url.Values, call ICallBack) error
- func (c *Client) PostJson(url string, value interface{}) IResponse
- func (c *Client) PostJsonAsyn(url string, value interface{}, call func(response IResponse)) error
- func (c *Client) PostJsonAsynWithCallback(url string, values interface{}, call ICallBack) error
- func (c *Client) PostMultipart(url string, body IMultipart) IResponse
- func (c *Client) PostMultipartAsyn(url string, body IMultipart, call func(response IResponse)) error
- func (c *Client) PostMultipartAsynWithCallback(url string, body IMultipart, call ICallBack) error
- func (c *Client) PostXml(url string, value interface{}) IResponse
- func (c *Client) PostXmlAsyn(url string, value interface{}, call func(response IResponse)) error
- func (c *Client) PostXmlAsynWithCallback(url string, values interface{}, call ICallBack) error
- func (c *Client) SendWithMethod(url, method string, body io.Reader, req func(request *http.Request)) IResponse
- func (c *Client) SendWithMethodCallBack(url, method string, body io.Reader, req func(request *http.Request), ...) error
- func (c *Client) SetCookies(cookies []*http.Cookie)
- func (c *Client) SetHeader(header map[string]string)
- type ClientBuilder
- func (builder *ClientBuilder) Build() (*Client, error)
- func (builder *ClientBuilder) BuildResponse(build BuildResponse) *ClientBuilder
- func (builder *ClientBuilder) Cert(cert []string) *ClientBuilder
- func (builder *ClientBuilder) CheckRedirect(checkRedirect CheckRedirect) *ClientBuilder
- func (builder *ClientBuilder) Cookie(cookie []*http.Cookie) *ClientBuilder
- func (builder *ClientBuilder) Header(header map[string]string) *ClientBuilder
- func (builder *ClientBuilder) Jar(options *cookiejar.Options) *ClientBuilder
- func (builder *ClientBuilder) ProxyUrl(u string) *ClientBuilder
- func (builder *ClientBuilder) SkipVerify(skip bool) *ClientBuilder
- func (builder *ClientBuilder) TimeOut(t time.Duration) *ClientBuilder
- func (builder *ClientBuilder) Tls(tlsPath []*TlsPath) *ClientBuilder
- type EasyMultipart
- type HttpResponse
- func (h *HttpResponse) Content() []byte
- func (h *HttpResponse) ContentLength() int64
- func (h *HttpResponse) Cookie(name string) *http.Cookie
- func (h *HttpResponse) Error() error
- func (h *HttpResponse) Header() http.Header
- func (h *HttpResponse) Request() *http.Request
- func (h *HttpResponse) Resp() *http.Response
- func (h *HttpResponse) StatusCode() int
- type ICallBack
- type IMultipart
- type IResponse
- type MultipartBuilder
- func (m *MultipartBuilder) AddBytes(name string, bytes []byte) *MultipartBuilder
- func (m *MultipartBuilder) AddFile(name, fileName string) *MultipartBuilder
- func (m *MultipartBuilder) AddFromDate(name, value string) *MultipartBuilder
- func (m *MultipartBuilder) Builder() (*EasyMultipart, error)
- func (m *MultipartBuilder) FromDate(value map[string]string) *MultipartBuilder
- type MultipartDateContent
- type MultipartDateType
- type TlsPath
Constants ¶
const ( //chrome pc HTTP_USER_AGENT_CHROME_PC = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11" //chrome mobile HTTP_USER_AGENT_CHROME_MOBILE = "" /* 147-byte string literal not displayed */ //Firefox pc HTTP_USER_AGENT_FIREFOX_PC = "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" //Firefox Mobil HTTP_USER_AGENT_FIREFOX_MOBLIE = "Mozilla/5.0 (Androdi; Linux armv7l; rv:5.0) Gecko/ Firefox/5.0 fennec/5.0" //IE11 HTTP_USER_AGENT_IE11 = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko" )
User-agent
const ( HTTP_CONTENT_TYPE_FROM_DATA = "application/x-www-form-urlencoded" HTTP_CONTENT_TYPE_TEXT = "text/plain" HTTP_CONTENT_TYPE_JSON = "application/json" HTTP_CONTENT_TYPE_XML = "application/xml" )
Content-Type
Variables ¶
This section is empty.
Functions ¶
func EasyPostJsonRequest ¶
POST请求中,处理request的函数,设置`Content-Type` 为 json
func EasyPostXmlRequest ¶
POST请求中,处理request的函数,设置`Content-Type` 为 xml
Types ¶
type CheckRedirect ¶
request重定向的回调函数
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AddCookies ¶
为client添加cookie,原来的会保留,整个生命周期有效
func (*Client) GetAsynWithCallback ¶
GET 异步请求,使用接口回调
func (*Client) PostBytesAsyn ¶
func (c *Client) PostBytesAsyn(url string, value []byte, req func(request *http.Request), call func(response IResponse)) error
post 的bytes请求
func (*Client) PostFormAsyn ¶
Post form 异步请求,使用回调函数
func (*Client) PostFormAsynWithCallback ¶
Post form 异步请求,使用接口回调
func (*Client) PostJsonAsyn ¶
Post json 异步请求,使用回调函数
func (*Client) PostJsonAsynWithCallback ¶
Post json 异步请求,使用接口回调
func (*Client) PostMultipart ¶
func (c *Client) PostMultipart(url string, body IMultipart) IResponse
post 的multipart请求
func (*Client) PostMultipartAsyn ¶
func (c *Client) PostMultipartAsyn(url string, body IMultipart, call func(response IResponse)) error
post 的multipart请求,使用回调函数
func (*Client) PostMultipartAsynWithCallback ¶
func (c *Client) PostMultipartAsynWithCallback(url string, body IMultipart, call ICallBack) error
post 的multipart请求,使用接口回调
func (*Client) PostXmlAsyn ¶
Post xml 异步请求,使用回调函数
func (*Client) PostXmlAsynWithCallback ¶
Post xml 异步请求,使用接口回调
func (*Client) SendWithMethod ¶
func (c *Client) SendWithMethod(url, method string, body io.Reader, req func(request *http.Request)) IResponse
指定请求的方法,发送请求 `req` 参数 可以处理这次请求的request
func (*Client) SendWithMethodCallBack ¶
func (c *Client) SendWithMethodCallBack(url, method string, body io.Reader, req func(request *http.Request), call func(response IResponse)) error
使用异步回调的方式,指定请求的方法,发送请求 `req` 参数 可以处理这次请求的request `call` 参数,请求成功后的回调函数
func (*Client) SetCookies ¶
为client设置新的cookie,原来的会删除,整个生命周期有效
type ClientBuilder ¶
type ClientBuilder struct {
// contains filtered or unexported fields
}
client 构造器 用来初始化一个client 不建议直接new client使用
func (*ClientBuilder) BuildResponse ¶
func (builder *ClientBuilder) BuildResponse(build BuildResponse) *ClientBuilder
func (*ClientBuilder) Cert ¶
func (builder *ClientBuilder) Cert(cert []string) *ClientBuilder
func (*ClientBuilder) CheckRedirect ¶
func (builder *ClientBuilder) CheckRedirect(checkRedirect CheckRedirect) *ClientBuilder
func (*ClientBuilder) Cookie ¶
func (builder *ClientBuilder) Cookie(cookie []*http.Cookie) *ClientBuilder
func (*ClientBuilder) Header ¶
func (builder *ClientBuilder) Header(header map[string]string) *ClientBuilder
func (*ClientBuilder) Jar ¶
func (builder *ClientBuilder) Jar(options *cookiejar.Options) *ClientBuilder
func (*ClientBuilder) ProxyUrl ¶
func (builder *ClientBuilder) ProxyUrl(u string) *ClientBuilder
func (*ClientBuilder) SkipVerify ¶
func (builder *ClientBuilder) SkipVerify(skip bool) *ClientBuilder
func (*ClientBuilder) TimeOut ¶
func (builder *ClientBuilder) TimeOut(t time.Duration) *ClientBuilder
func (*ClientBuilder) Tls ¶
func (builder *ClientBuilder) Tls(tlsPath []*TlsPath) *ClientBuilder
type EasyMultipart ¶
type EasyMultipart struct {
// contains filtered or unexported fields
}
func (*EasyMultipart) ContentType ¶
func (m *EasyMultipart) ContentType() string
type HttpResponse ¶
type HttpResponse struct { ResponseContent []byte // contains filtered or unexported fields }
func (*HttpResponse) Content ¶
func (h *HttpResponse) Content() []byte
func (*HttpResponse) ContentLength ¶
func (h *HttpResponse) ContentLength() int64
func (*HttpResponse) Error ¶
func (h *HttpResponse) Error() error
func (*HttpResponse) Header ¶
func (h *HttpResponse) Header() http.Header
func (*HttpResponse) Request ¶
func (h *HttpResponse) Request() *http.Request
func (*HttpResponse) Resp ¶
func (h *HttpResponse) Resp() *http.Response
func (*HttpResponse) StatusCode ¶
func (h *HttpResponse) StatusCode() int
type IMultipart ¶
用于 post multipart 的接口
type IResponse ¶
type IResponse interface { //返回这个请求的错误 Error() error //返回这个请求的http状态码 StatusCode() int //返回HTTP请求的header信息 Header() http.Header //返回HTTP内容长度 ContentLength() int64 //返回HTTP的内容 Content() []byte //返回HTTP包中的 response信息 Resp() *http.Response //返回这次请求的request信息 Request() *http.Request //根据name 返回response的cookie Cookie(name string) *http.Cookie }
使用client发去请求后,返回一个实现了这个接口的对象 只要实现这个接口,就能作为返回值 在 `BuildResponse` 函数中构造出返回的对象 默认提供了 `HttpResponse` 实现了这个接口 可以根据自己的需求自己重新实现这个接口
type MultipartBuilder ¶
type MultipartBuilder struct {
// contains filtered or unexported fields
}
用于构造一个 multipart
func (*MultipartBuilder) AddBytes ¶
func (m *MultipartBuilder) AddBytes(name string, bytes []byte) *MultipartBuilder
添加[]byte, name, form-data的name
func (*MultipartBuilder) AddFile ¶
func (m *MultipartBuilder) AddFile(name, fileName string) *MultipartBuilder
添加文件 name upload时的name fileName 文件的路径+文件名
func (*MultipartBuilder) AddFromDate ¶
func (m *MultipartBuilder) AddFromDate(name, value string) *MultipartBuilder
添加form-data数据
func (*MultipartBuilder) Builder ¶
func (m *MultipartBuilder) Builder() (*EasyMultipart, error)
构造 MultipartDate
func (*MultipartBuilder) FromDate ¶
func (m *MultipartBuilder) FromDate(value map[string]string) *MultipartBuilder
以map的形式 添加form-data数据, k=>form-data的name, v=>form-data的Valve
type MultipartDateContent ¶
type MultipartDateContent struct { Type MultipartDateType Content []byte }
用于 `MultipartBuilder` 中的内容记录
type MultipartDateType ¶
type MultipartDateType int8
const ( MultipartDateTypeFile MultipartDateType = iota MultipartDateTypeFormDate MultipartDateTypeContent )
MultipartDateType 的枚举