improve ghttp.Request for making the request body reusable for multiple times

This commit is contained in:
John
2020-02-06 11:14:38 +08:00
parent 1999ef95c1
commit 95411aff77
3 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"io/ioutil"
)
func main() {
s := g.Server()
s.SetIndexFolder(true)
s.BindHandler("/", func(r *ghttp.Request) {
body1 := r.GetBody()
body2, _ := ioutil.ReadAll(r.Body)
fmt.Println(body1)
fmt.Println(body2)
r.Response.Write("hello world")
})
s.SetPort(8999)
s.Run()
}