测试版本go1.4.2
resp, err := http.Get("http://example.com/")
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
fmt.Println("err: ", err)
return
}
_, err = ioutil.ReadAll(resp.Body) //去掉这句,则主动关闭连接 ???
从这里看到的解释: The orignal implementation for resp.Body.Close() also reads and discards the remaining response body data. This ensured that the http connection could be reused for another request if the keepalive http connection behavior is enabled. The latest http client behavior is different. Now it's your responsibility to read and discard the remaining response data. If you don't do it the http connection might be closed instead of being reused. This little gotcha is supposed to be documented in Go 1.5.
本文主要探讨了在Go 1.4.2版本中遇到的http关闭问题,详细分析了可能的原因和解决方案。
1281

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



