无法使用Revel检索表单参数。

huangapple go评论86阅读模式
英文:

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)
}

huangapple
  • 本文由 发表于 2016年2月29日 01:37:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/35685902.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定