fasthttp|fasthttp client example
说明
【fasthttp|fasthttp client example】官方文档关于fasthttp的demo基本都是http server, http client的介绍基本没有, 这里只写个client的示例。
参考源: http://big-elephants.com/2016-12/fasthttp-client/
client := fasthttp.Client{TLSConfig: &tls.Config{InsecureSkipVerify: true}}
req := fasthttp.AcquireRequest()
req.SetRequestURI("url")
req.Header.SetMethod("POST")
req.Header.Set("Content-Type", "application/json")
resp := fasthttp.AcquireResponse()
req.SetBodyString(`{"body": "json_str"}`)//设置请求参数
req.SetBody([]byte(`{"body": "sjon_str"}`)) //设置[]byte
if err := client.Do(req, resp);
err != nil {
fmt.Printf("loan list fail to do request. appID=%s. [err=%v]\n", h["X-PPD-APPID"], err)
continue
}
b := resp.Body()
if resp.StatusCode() != fasthttp.StatusOK {
fmt.Printf("loan list failed code=%d. [err=%v]\n", resp.StatusCode(), string(b))
continue
}
推荐阅读
- HttpClient对外部网络的操作
- Mockito|Mockito mock void methods Example
- C#中HttpClient使用注意(预热与长连接)
- kotlin|kotlin example
- Fescar|Fescar example解析 - TM发送逻辑
- 2018-10-17|2018-10-17 XPath Examples
- HttpClient 设置不当引发的一次雪崩!
- HTTPClient在Springboot中封装的工具类
- Spring|Spring-Cloud-Eureka-Client 服务调用
- 【译】Redis 客户端缓存 (Redis server-assisted client side caching)