使用fasthttp 请求网络资源,fasthttp http Client 的使用例子
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
package main
import (
"fmt"
"github.com/valyala/fasthttp"
)
func main() {
url := "http://www.golangnote.com/"
client := &fasthttp.Client{}
request := fasthttp.AcquireRequest()
response := fasthttp.AcquireResponse()
defer fasthttp.ReleaseRequest(request)
defer fasthttp.ReleaseResponse(response)
request.SetConnectionClose()
request.SetRequestURI(url)
if err := client.Do(request, response); err != nil {
fmt.Println(err)
} else {
fmt.Println(string(response.Header.Header()))
fmt.Println(string(response.Body()))
}
}
本文网址: https://golangnote.com/topic/169.html 转摘请注明来源