[[TOC]]
基于fasthttp的http请求客户端,用于快速构建http请求
- 2020-12-15
- 修复get时url自带query导致最后加了一个?的bug
- 2020-12-14
- 返回添加header
- 重新设计了请求时入参的结构(param,header,cookie等)
- get
- post
- sendFile
- 支持使用tls
- 支持proxy(全局)
-
get
res, err = NewClient(). AddParam("param1", "param1"). AddParams( NewParams(). Set("param2", "param2"). Set("param3", "param3")). AddHeader("header1", "header1"). AddHeaders( NewHeaders(). Set("header2", "header2"). Set("header3", "header3")). AddCookie("cookie1", "cookie1"). AddCookies( NewCookies(). Set("cookie1", "cookie1"). Set("cookie2", "cookie2")). Get("http://httpbin.org/get")
-
post
res, err = NewClient(). AddBodyStruct( struct { Request string `json:"request" form:"request"` Num int `json:"num"` }{ Request: "test", Num: 1, }, ). AddHeader("header1", "header1"). AddHeaders( NewHeaders(). Set("header2", "header2"). Set("header3", "header3"), //"content-type": "application/json", ). AddCookie("cookie1", "cookie1"). AddCookies(NewCookies(). Set("cookie1", "cookie1"). Set("cookie2", "cookie2")). Post("http://httpbin.org/post")
-
sendFile
res, err = NewClient(). AddFile("a", "/Users/chuwt/Downloads/test.jpg"). AddFiles( NewFiles(). Set("b", "/Users/chuwt/Downloads/test.jpg"), ). SendFile("http://httpbin.org/post")
-
tls
client = NewClient() client.SetCrt(certPath, certKey).Get("")
-
ps
- client.SetTimeout 非线程安全,倾向于做为全局(实例)配置使用
- client.SetCrt 非线程安全,倾向于做为全局(实例)配置使用
-
说明
- 单个请求的proxy 支持