HTTP 客户端请求包 Go-Request

码农软件 · 软件分类 · 网络工具包 · 2019-02-26 12:41:32

软件介绍

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")


本文地址:https://codercto.com/soft/d/171.html

算法笔记

算法笔记

胡凡、曾磊 / 机械工业出版社 / 2016-7 / 65

这是一本零基础就能读懂的算法书籍,读者不需要因为自己没有语言基础而畏惧。书籍的第2章便是一个C语言的入门教程,内容非常易懂,并且十分实用,阅读完这章就可以对本书需要的C语言基础有一个较好的掌握。 本书已经覆盖了大部分基础经典算法,不仅可以作为考研机试和PAT的学习教材,对其他的一些算法考试(例如CCF的CSP考试)或者考研初试的数据结构科目的学习和理解也很有帮助,甚至仅仅想学习经典算法的读者......一起来看看 《算法笔记》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具