当我在Grails上调用Post方法时,params是空的

时间:2013-05-15 13:47:24

标签: web-services grails

我正在为我的应用程序编写webservices。 我的问题是,当我使用GET方法调用它时,它可以工作,但是当我使用POST方法时,params不包含我的参数的ant:

当我使用GET调用时,这是params的内容:

params : [username:azerty, test:test, param2:param2, action:editProfile, controller:userWebService]

当我使用POST调用时,这是params的内容:

params : [action:editProfile, controller:userWebService]

编辑:

/* user controller */
"/service/$action?"(controller: "userWebService", parseRequest: true)
UserWebServiceController

中的

....
static allowedMethods = [editProfile:['POST', 'GET']]
....
def editProfile(){

    println "params : "+ params
....
}

测试我在chrome中使用REST控制台插件

enter image description here

1 个答案:

答案 0 :(得分:4)

params不同,{p> POST不会作为GET次请求中的查询字符串发送。如果POST请求,则必须将参数字符串嵌入请求正文中。

使用content-typeapplication/x-www-form-urlencoded

并在request-body中使用
username=azerty&test=test

您应该能够在控制器内的params中看到参数。

enter image description here

你应该能够看到
params : [age:25, name:Hamila, action:editProfile, controller:userWebService]

我在测试中让你看起来更年轻吗? :)