-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (34 loc) · 843 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"github.com/zhangdapeng520/zdpgo_fasthttp"
)
/*
@Time : 2022/6/22 15:53
@Author : 张大鹏
@File : main.go
@Software: Goland2021.3.1
@Description:
*/
func main() {
url := `http://httpbin.org/post?key=123`
req := zdpgo_fasthttp.AcquireRequest()
resp := zdpgo_fasthttp.AcquireResponse()
defer func() {
// 用完需要释放资源
zdpgo_fasthttp.ReleaseResponse(resp)
zdpgo_fasthttp.ReleaseRequest(req)
}()
// 默认是application/x-www-form-urlencoded
req.Header.SetContentType("application/json")
req.Header.SetMethod("POST")
req.SetRequestURI(url)
requestBody := []byte(`{"request":"test"}`)
req.SetBody(requestBody)
if err := zdpgo_fasthttp.Do(req, resp); err != nil {
fmt.Println("请求失败:", err.Error())
return
}
b := resp.Body()
fmt.Println("result:\r\n", string(b))
}