Tuesday, January 21, 2025
HomeGolangFinest deal with of http response? - Getting Assist

Finest deal with of http response? – Getting Assist


A regular http req like:

	information, _ := json.Marshal(map[string]any{
		"passwd": "123",
		"identify":   "xx",
	})
	req, err := http.Publish("http://localhost:8085/login", "utility/json", bytes.NewReader(information))
	if err != nil {
		panic(err)
	}
	defer req.Physique.Shut()
	io.Copy(io.Discard, req.Physique) // should ?

I would like do many http requests.If i don’t care respone ,ought to i take advantage of io.Copy(io.Discard, req.Physique) ?
I see some articles says resp.Physique.Shut() will reads and discards the remaining response physique information.

Simply shut the physique instantly, you don’t must assume an excessive amount of.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments