GolangNote

Golang笔记

使用fasthttp 请求网络资源

Permalink

使用fasthttp 请求网络资源,fasthttp http Client 的使用例子

Go: 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 转摘请注明来源

Related articles

golang snappy 的使用场合

google 自家的 snappy 压缩优点是非常高的速度和合理的压缩率。压缩率比 gzip 小,CPU 占用小。...

bolt 使用示例

bolt 是一款高性能的key value 数据库,下面是它的使用示例:...

groupcache 使用入门

groupcache 是 memcached 作者 Brad Fitzpatrick 用 Go 语言编写的缓存及缓存过滤库,作为 memcached 许多场景下的替代版本。...

Write a Comment to "使用fasthttp 请求网络资源"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.20 Processed in 0ms