最佳答案
在 Go 中,我有一些 http 回复,有时我会忘记打电话:
resp.Body.Close()
这种情况下会发生什么?会有内存泄漏吗?在得到响应对象之后立即放入 defer resp.Body.Close()
是否安全?
client := http.DefaultClient
resp, err := client.Do(req)
defer resp.Body.Close()
if err != nil {
return nil, err
}
如果出现错误,resp
或 resp.Body
是否为零?