Best handle of http response?

A standard http req like:

	data, _ := json.Marshal(map[string]any{
		"passwd": "123",
		"name":   "xx",
	})
	req, err := http.Post("http://localhost:8085/login", "application/json", bytes.NewReader(data))
	if err != nil {
		panic(err)
	}
	defer req.Body.Close()
	io.Copy(io.Discard, req.Body) // must ?

I need do many http requests.If i don’t care respone ,should i use io.Copy(io.Discard, req.Body) ?
I see some articles says resp.Body.Close() will reads and discards the remaining response body data.

Just close the body directly, you don’t need to think too much.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.