gin获取前端发送的Request Payload的值

buf := make([]byte, 1024)
n, _ := c.Request.Body.Read(buf)
c.Request.Body = ioutil.NopCloser(bytes.NewReader(buf[:n]))
j := buf[0:n]
fmt.Println("body:", string(j)+"a") //获取到post传递过来的数据
admin_admin := models.Admin_admin{}
err := json.Unmarshal(j, &admin_admin)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(admin_admin.Username)
posted @ 2020-11-19 16:22  程序员小艺  阅读(1201)  评论(0编辑  收藏  举报