mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
improve ghttp.Request for making the request body reusable for multiple times
This commit is contained in:
22
.example/net/ghttp/server/body.go
Normal file
22
.example/net/ghttp/server/body.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user