go读取http.Request中body的内容

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()) 

  

posted @ 2021-09-08 13:14  delphi中间件  阅读(1709)  评论(0)    收藏  举报