配置文件中配置了
copyrequestbody = true
请求是有localhost:8080向localhost:8088(服务端)请求的,beego中配置了跨域
页面请求:
this.$axios.post("user",{
username:"123",
passowrd:"321"
})
beego路由解析
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
AllowCredentials: true,
}))
beego.Router("/user/?:id", &userController.UserController{})
beego中解析如下
type user struct {
nickname string
username string
password string
}
func (this *UserController) Post() {
u := user{} //空的
c := this.Input().Get("phone") //空的
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &u); err == nil {
fmt.Println(u.password)
fmt.Println(c)
}
}
打断点能看到this.Ctx.Input.RequestBody的len是83
页面请求Network中也能看到数据:如下图。
可就是解析不到数据