golang http request 读两次body

方法是body重新赋值,

bodyBytes, _ := ioutil.ReadAll(req.Body)
req.Body.Close()  //  must close
req.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))

看了三个网页,都是这样做的:
https://stackoverflow.com/questions/46948050/how-to-read-response-body-twice-in-golang-middleware
https://medium.com/@xoen/golang-read-from-an-io-readwriter-without-loosing-its-content-2c6911805361
http://blog.manugarri.com/how-to-reuse-http-response-body-in-golang/

猜你喜欢

转载自blog.csdn.net/harryhare/article/details/80657849