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

Finest deal with of http response? – Getting Assist


A normal http req like:

	knowledge, _ := json.Marshal(map[string]any{
		"passwd": "123",
		"identify":   "xx",
	})
	req, err := http.Submit("http://localhost:8085/login", "utility/json", bytes.NewReader(knowledge))
	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 knowledge.

Simply shut the physique instantly, you don’t have to suppose an excessive amount of.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments