Go语言HTTP请求配置与处理全解析
1. 配置HTTP请求
Go语言为用户代理与HTTP服务器的通信提供了底层接口。使用这个接口,能让你对客户端请求有更多的控制权,但同时也需要你花费更多精力来构建请求,不过复杂度的提升并不大。
构建请求使用的数据类型是 Request ,其结构如下:
type Request struct {
Method string
URL *url.URL
Proto string // "HTTP/1.0"
ProtoMajor int // 1
ProtoMinor int // 0
Header Header
Body io.ReadCloser
GetBody func() (io.ReadCloser, error)
ContentLength int64
TransferEncoding []string
Close bool
Host string
Form url.Values
PostForm url.Values
MultipartForm *multipart.Form
Trailer Header
RemoteAddr string
RequestURI string
TLS *tls.ConnectionState
Cancel <-chan struct{}
Response *Response
}
相关方法如下:
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



