go的 response 学习
来源:互联网 发布:一角书屋知乎 编辑:程序博客网 时间:2024/06/06 09:18
response代表来自http request的响应
先看看response的结构体定义
type Response struct { Status string // e.g. "200 OK" StatusCode int // e.g. 200 Proto string // e.g. "HTTP/1.0" ProtoMajor int // e.g. 1 ProtoMinor int // e.g. 0 // Header maps header keys to values. If the response had multiple // headers with the same key, they may be concatenated, with comma // delimiters. (Section 4.2 of RFC 2616 requires that multiple headers // be semantically equivalent to a comma-delimited sequence.) Values // duplicated by other fields in this struct (e.g., ContentLength) are // omitted from Header. // // Keys in the map are canonicalized (see CanonicalHeaderKey). Header Header // The http Client and Transport guarantee that Body is always // non-nil, even on responses without a body or responses with // a zero-length body. It is the caller's responsibility to // close Body. The default HTTP client's Transport does not // attempt to reuse HTTP/1.0 or HTTP/1.1 TCP connections // ("keep-alive") unless the Body is read to completion and is // closed. // // The Body is automatically dechunked if the server replied // with a "chunked" Transfer-Encoding. Body io.ReadCloser // response body部分 ,读完之后就被关闭 ContentLength int64 // 表示传输的文本长度 // Contains transfer encodings from outer-most to inner-most. Value is // nil, means that "identity" encoding is used. TransferEncoding []string Close bool // Trailer maps trailer keys to values in the same // format as Header. // // The Trailer initially contains only nil values, one for // each key specified in the server's "Trailer" header // value. Those values are not added to Header. // // Trailer must not be accessed concurrently with Read calls // on the Body. // // After Body.Read has returned io.EOF, Trailer will contain // any trailer values sent by the server. Trailer Header // The Request that was sent to obtain this Response. // Request's Body is nil (having already been consumed). // This is only populated for Client requests. Request *Request // TLS contains information about the TLS connection on which the // response was received. It is nil for unencrypted responses. // The pointer is shared between responses and should not be // modified. TLS *tls.ConnectionState
方法调用
func Get(url string) (resp *Response, err error) func Head(url string) (resp *Response, err error) func Post(url string, bodyType string, body io.Reader) (resp *Response, err error) func PostForm(url string, data url.Values) (resp *Response, err error) func ReadResponse(r *bufio.Reader, req *Request) (*Response, error) func (r *Response) Cookies() []*Cookie func (r *Response) Location() (*url.URL, error) func (r *Response) ProtoAtLeast(major, minor int) bool func (r *Response) Write(w io.Writer) error
0 0
- go的 response 学习
- 【Go学习】Go的函数
- 学习GO的原因
- Go语言的学习
- go的request学习
- 学习的开端—GO!GO!
- go的学习资料点评
- go unsafe package 的学习
- 爬虫学习01 requests入门 response的常用方法 response.text 和response.content的区别
- 有关asp.net的response的学习
- 【Go】Go学习-WebSocket
- Go语言学习5:Go语言的变量类型
- Go语言学习笔记(一) [Go语言的HelloWorld]
- Go语言学习:安装本地的Go入门教程
- GO语言学习:go语言实现android应用的步骤
- request和response的学习总结
- 10 request&&response的学习笔记
- javascript: history.go(-1)和response.redirect();
- 初学结构体
- ZCMU—1067
- Parallel Reduction --- (2) Remove Unnecessary Modular Arithmetic
- Android系统源代码编译—[4]运行构建
- 最小割的一些性质和理解
- go的 response 学习
- eclipse 中项目打包成jar以及exe文件
- JS 原型理解
- html笔记
- the SetStack computer
- jottings-ubuntu16.04 lts的完整克隆
- String,StringBuffer和StringBuilder的区别
- 线程让步(六)
- python数据结构学习笔记-2016-12-03-01-堆排序