A Go “clone” of the great and famous Requestslibrary
文档
安装依赖
go mod init requests-demo go get -u github.com/levigross/grequests
代码示例
package main import ( "fmt" "github.com/levigross/grequests" ) func main() { // 请求参数 options := &grequests.RequestOptions{ Params: map[string]string{ "name": "Tom", "age": "20", }, } resp, _ := grequests.Get("http://httpbin.org/get", options) if resp.Ok { fmt.Println(resp.String()) } }
输出结果
{ "args": { "age": "20", "name": "Tom" }, "headers": { "Accept-Encoding": "gzip", "Host": "httpbin.org", "User-Agent": "GRequests/0.10", "X-Amzn-Trace-Id": "Root=1-64190bc5-1b1798e46aaffd4658f84da3" }, "origin": "1.202.253.34", "url": "http://httpbin.org/get?age=20&name=Tom" }
其他同类库