【文件属性】:
文件名称:HTTP客户端请求包Go-Request.zip
文件大小:24KB
文件格式:ZIP
更新时间:2022-08-06 16:10:25
开源项目
Go-Request 是 HTTP 客户端请求包,灵感来源于 Python Requests。
安装
go get -u github.com/mozillazg/request
文档
API 文档:https://godoc.org/github.com/mozillazg/request
使用
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.Data = map[string]string{
"key": "value",
"a": "123",
}
resp, err := req.Post("http://httpbin.org/post")
Cookies:
req.Cookies = map[string]string{
"key": "value",
"a": "123",
}
resp, err := req.Get("http://httpbin.org/cookies")
Headers:
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:
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.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.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.BasicAuth = request.BasicAuth{"user", "passwd"}
resp, err := req.Get("http://httpbin.org/basic-auth/user/passwd")
标签:GoRequest
【文件预览】:
request-master
----.travis.yml(1KB)
----response_test.go(2KB)
----redirect.go(767B)
----_example()
--------timeout()
--------hooks_dump()
--------proxy()
--------login()
----doc.go(2KB)
----headers.go(1KB)
----.github()
--------CONTRIBUTING.md(231B)
----cookies_test.go(447B)
----example_test.go(3KB)
----response.go(2KB)
----hook_test.go(4KB)
----redirect_test.go(2KB)
----LICENSE(1KB)
----proxy_test.go(924B)
----headers_test.go(690B)
----request_test.go(6KB)
----glide.yaml(519B)
----proxy.go(802B)
----.gitignore(298B)
----form_test.go(5KB)
----CHANGELOG.md(2KB)
----Makefile(194B)
----cookies.go(301B)
----README.md(3KB)
----.editorconfig(416B)
----form.go(2KB)
----Godeps()
--------Godeps.json(869B)
--------Readme(136B)
----request.go(8KB)
----proxy_go12.go(779B)
----hook.go(1016B)