mozillazg/request
Fork: 40 Star: 425 (更新于 2024-11-19 20:04:49)
license: MIT
Language: Go .
A developer-friendly HTTP request library for Gopher.
最后发布版本: v0.8.0 ( 2016-12-25 21:40:02)
request
A developer-friendly HTTP request library for Gopher. Inspired by Python-Requests.
Installation
go get -u github.com/mozillazg/request
Documentation
API documentation can be found here: https://godoc.org/github.com/mozillazg/request
Usage
import (
"github.com/mozillazg/request"
)
GET:
c := new(http.Client)
req := request.NewRequest(c)
resp, err := req.Get("http://httpbin.org/get")
j, err := resp.Json()
defer resp.Body.Close() // Don't forget close the response body
POST:
req := request.NewRequest(c)
req.Data = map[string]string{
"key": "value",
"a": "123",
}
resp, err := req.Post("http://httpbin.org/post")
Cookies:
req := request.NewRequest(c)
req.Cookies = map[string]string{
"key": "value",
"a": "123",
}
resp, err := req.Get("http://httpbin.org/cookies")
Headers:
req := request.NewRequest(c)
req.Headers = map[string]string{
"Accept-Encoding": "gzip,deflate,sdch",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
}
resp, err := req.Get("http://httpbin.org/get")
Files:
req := request.NewRequest(c)
f, err := os.Open("test.txt")
req.Files = []request.FileField{
request.FileField{"file", "test.txt", f},
}
resp, err := req.Post("http://httpbin.org/post")
Json:
req := request.NewRequest(c)
req.Json = map[string]string{
"a": "A",
"b": "B",
}
resp, err := req.Post("http://httpbin.org/post")
req.Json = []int{1, 2, 3}
resp, err = req.Post("http://httpbin.org/post")
Proxy:
req := request.NewRequest(c)
req.Proxy = "http://127.0.0.1:8080"
// req.Proxy = "https://127.0.0.1:8080"
// req.Proxy = "socks5://127.0.0.1:57341"
resp, err := req.Get("http://httpbin.org/get")
or https://github.com/mozillazg/request/tree/develop/_example/proxy
HTTP Basic Authentication:
req := request.NewRequest(c)
req.BasicAuth = request.BasicAuth{"user", "passwd"}
resp, err := req.Get("http://httpbin.org/basic-auth/user/passwd")
License
Under the MIT License.
最近版本更新:(数据更新于 2024-10-03 00:40:54)
2016-12-25 21:40:02 v0.8.0
2016-11-07 22:45:38 v0.7.0
2016-09-04 20:34:37 v0.6.0
2016-06-05 21:18:42 v0.5.1
2015-11-15 22:19:36 v0.5.0
2015-11-15 22:09:42 v0.4.0
2015-09-29 16:52:01 v0.3.1
主题(topics):
go, golang, http, request
mozillazg/request同语言 Go最近更新仓库
2024-11-22 20:14:47 daytonaio/daytona
2024-11-22 15:17:23 SagerNet/sing-box
2024-11-21 22:49:20 containerd/containerd
2024-11-21 13:50:50 XTLS/Xray-core
2024-11-21 07:36:18 kubernetes/kubernetes
2024-11-21 06:27:30 ollama/ollama