Go (Golang) 语言读取 http.Request 中 body 的内容

不罗嗦了,直接贴代码,不晓得为什么搞这么复杂,是不是因为担心 body 内容一次接受不全,所以搞了个接口来读取其中的内容?

import (
    ...
    "io/ioutil"
    ...
)

...

func myPost(w http.ResponseWriter, r *http.Request) {
    s, _ := ioutil.ReadAll(r.Body) //把  body 内容读入字符串 s
    fmt.Fprintf(w, "%s", s)        //在返回页面中显示内容。
}

...

猜你喜欢

转载自blog.csdn.net/quicmous/article/details/80068161