web-services - 当我在 Grails 上调用 Post 方法时,params 为空

标签 web-services grails

我正在为我的应用程序编写网络服务。
我的问题是,当我使用 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

最佳答案

paramsPOST 中不会作为查询字符串发送请求不同于 GET .在 POST 的情况下,参数字符串必须嵌入到请求正文中要求。

使用 content-type :application/x-www-form-urlencoded
并在 request-bodyusername=azerty&test=test
您应该可以看到 params 中的参数 Controller 内部。

enter image description here

你应该能够看到params : [age:25, name:Hamila, action:editProfile, controller:userWebService]
我让你在考试中看起来更年轻了吗? :)

关于web-services - 当我在 Grails 上调用 Post 方法时,params 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16566818/

相关文章:

java - 启动 soapUi 3.01 时出错

sql - 将查询结果返回到 Grails 中的 View

Grails-如何获取不同用户对象的列表

java - Axis2 Web 服务故障 - 找不到端点引用的服务

java - 在 Play Web 服务中使用 GET 参数?

java - 将自定义对象作为 Web 服务的参数发送

java - EJB WebService (JAX-WS) 的 WSDL 的 URL 是什么?

Grails 和 Groovy 元类包名称约定

tomcat - 在 Tomcat 中获取 WebUtils.retrieveGrailsWebRequest()

postgresql - Grails中的URL映射,除根名外不应显示其他任何内容