用的postman做请求,结果打印出来的总是空值,配置文件加载了copyrequestbody = true,来个大神指导下
package controllers
import (
"github.com/astaxie/beego"
"fmt"
"encoding/json"
)
type MainController struct {
beego.Controller
}
type User struct{
username string `json:"username"`
password string `json:"password"`
}
func (c *MainController) Post() {
ob := User{}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &ob);err == nil {
fmt.Printf("%+v\n", ob)
}
// fmt.Println(c.Ctx.Input.RequestBody)
//fmt.Printf("%+v\n", ob)
}
有疑问加站长微信联系(非本文作者)