go读取http.Request中body的内容
时间:2021-09-09 20:45:18
收藏:0
阅读:41
go读取http.Request中body的内容
第一种方法:
import (
"io/ioutil"
)
func myPost(w http.ResponseWriter, r *http.Request) {
s, _ := ioutil.ReadAll(r.Body) //把 body 内容读入字符串 s
fmt.Fprintf(w, "%s", s) //在返回页面中显示内容。
}
第二种方法:
buf := new(bytes.Buffer) buf.ReadFrom(r.Body) fmt.Println(buf.String())
原文:https://www.cnblogs.com/hnxxcxg/p/15242307.html
评论(0)