Golang在http.Request中保留了请求“ body”的痕迹

This question already has an answer here:

My error is well explain here : https://github.com/golang/go/issues/17088

I don't know if it's a misunderstanding of the concept of http package but I fail to return the "body" (the parameters that my POST request send) of a request after the request is sent (client.Do) .. .

Example :

func showRequestBody(r *http.Request) {
  fmt.Println(r)
  fmt.Println(r.Body)
}

Give me an empty map or when I do : r.Form or r.PostForm it's nil or empty.

Thanks :) (More info and great code highlight on the github link)

</div>

The Body isn't a string but a Reader (more specifically a ReadCloser). When you read some byte, you take it from the stream, you can't read it again.

If you really need to intercept the Body before sending it, and can't read again from the source, a solution would be to read it into a buffer before reconstructing a new ReadCloser from the buffer.

EDIT: at this point I realize this is mostly a duplicate of Reading body of http.Request without modifying request state? and I vote to close as such. I might delete the answer if it brings nothing.