百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

grequests

> 包管理
开源

一个基于 Go 的「克隆」版本,源自伟大而著名的 Requests 库

2.2K stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个基于 Go 的「克隆」版本,源自伟大而著名的 Requests 库

GRequests

GRequests 为 Go 的 net/http 包提供了一个干净的包装。 它模仿了 Python Requests 库的便利性,同时保持了 Go 的强大和安全性。

特性

  • 为每个 HTTP 动词提供简单的辅助函数
  • 具备上下文感知请求功能,可轻松取消
  • 请求选项,用于头部、查询参数、代理、Cookie 等
  • 为 JSON 和 XML 响应提供内置支持
  • 文件上传和方便的下载辅助工具
  • 请求之间重用 Cookie 的会话类型

安装

bash
go get github.com/levigross/grequests/v2

快速入门

go
package main

import (
    "context"
    "log"

    "github.com/levigross/grequests/v2"
)

func main() {
    resp, err := grequests.Get(context.Background(), "https://httpbin.org/get",
        grequests.UserAgent("MyAgent"))
    if err != nil {
        log.Fatal(err)
    }

    var data map[string]any
    if err := resp.JSON(&data); err != nil {
        log.Fatal(err)
    }
    log.Println(data)
}

上传文件

go
fd, _ := grequests.FileUploadFromDisk("testdata/file.txt")
ro := &grequests.RequestOptions{
    Files: fd,
    Data:  map[string]string{"desc": "test"},
}
resp, err := grequests.Post(context.Background(), "https://httpbin.org/post",
    grequests.FromRequestOptions(ro))

使用会话

go
sess := grequests.NewSession(nil)
_, _ = sess.Get(context.Background(), "https://httpbin.org/cookies/set?one=two", nil)
resp, _ := sess.Get(context.Background(), "https://httpbin.org/cookies", nil)
log.Println(resp.String())

请参阅文档以查看可用选项的完整列表。

许可证

GRequests 遵循 Apache 许可证 2.0 版发行。详细信息请参阅 LICENSE。

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gogolanggolang-packagegrequestshttp-client

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image