GO beego 部署时出现Error:unexpected end of JSON input
beego Error: unexpected end of JSON input
1、Note
在日常的Api开发中,我们经常会使用Json来作为数据交互的方式,特别是前后端分离后
此时,如何在beego中获取 Request Body 的内容呢?
官方配置
1、在配置文件中添加 copyrequestbody = true
2、在controller 使用this.Ctx.Input.RequestBody获取Body数据, 然后利用json.Unmarshal 解析 Request Body的数据
func (this *ObjectController) Post() {
var ob models.Object
var err error
if err = json.Unmarshal(this.Ctx.Input.RequestBody, &ob); err == nil {
objectid := models.AddOne(ob)
this.Data[“json”] = “{“ObjectId”:”" + objectid + “”}"
} else {
this.Data[“json”] = err.Error()
}
this.ServeJSON()
}
但在开发中这样确实没有问题,但编译