MyGit

mozillazg/request

Fork: 40 Star: 425 (更新于 2024-10-28 10:59:20)

license: MIT

Language: Go .

A developer-friendly HTTP request library for Gopher.

最后发布版本: v0.8.0 ( 2016-12-25 21:40:02)

官方网址 GitHub网址

request

Build Status Coverage Status Go Report Card GoDoc

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-12 11:57:47 SagerNet/sing-box

2024-11-12 01:42:15 AlexxIT/go2rtc

2024-11-11 12:25:39 XTLS/Xray-core

2024-11-09 20:08:42 danielmiessler/fabric

2024-11-09 05:00:29 SpecterOps/BloodHound

2024-11-09 03:58:30 ollama/ollama