英文:
Can't retrieve form params with Revel
问题
我无法使用Revel检索表单数据,但我可以检索查询参数。
我有一个控制器来测试c.Params的内容:
func (c UserController) SaveUser() revel.Result {
    return c.RenderJson(c.Params) // 仅用于检查内容
}
当我传递一个查询参数(testkey,value)时,我得到以下结果:
{
  "Values": {
    "testkey": [
      "value"
    ]
  },
  "Fixed": null,
  "Route": null,
  "Query": {
    "testkey": [
      "value"
    ]
  },
  "Form": null,
  "Files": null
}
一切正常。但是当我传递一个表单参数时,我没有得到任何数据:
{
  "Values": {},
  "Fixed": null,
  "Route": null,
  "Query": {},
  "Form": null,
  "Files": null
}
这是一个PUT请求,我正在使用Postman传递表单参数。
谢谢。
英文:
I can't retrieve the form data using Revel. I'm able to retrieve query params though.
I have this controller to test the content of c.Params:
func (c UserController) SaveUser() revel.Result {
    return c.RenderJson(c.Params) //just for check the content
}
When I pass a query param (testkey, value) I get:
{
  "Values": {
    "testkey": [
      "value"
    ]
  },
  "Fixed": null,
  "Route": null,
  "Query": {
    "testkey": [
      "value"
    ]
  },
  "Form": null,
  "Files": null
}
Everything ok. But when I pass a form param and I don't get any data:
{
  "Values": {},
  "Fixed": null,
  "Route": null,
  "Query": {},
  "Form": null,
  "Files": null
}
It is a PUT request and I'm using Postman to pass form params.
Thanks.
答案1
得分: 0
我找到了解决方案。我必须将表单参数作为方法参数传递:
// id和nickname是表单参数
func (c UserController) SaveUser(id, nickname string) revel.Result {
    return c.RenderJson(c.Params)
}
英文:
I found the solution. I had to pass form params as method parameters:
// id and nickname are form params
func (c UserController) SaveUser(id, nickname string) revel.Result {
    return c.RenderJson(c.Params)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论