Params is empty when I call the Post method on Grails

I am writing web services for my application. my problem is that when I call it using the GET method, it works, but when I use the POST method, the parameters do not contain ant of my parameters:

when I call with GET, this is the contents of the parameters:

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

when I call using POST, this is the contents of the parameters:

 params : [action:editProfile, controller:userWebService] 

EDIT:

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

in UserWebServiceController

 .... static allowedMethods = [editProfile:['POST', 'GET']] .... def editProfile(){ println "params : "+ params .... } 

to verify that I am using the REST console plugin in chrome

enter image description here

+4
source share
1 answer

params not sent as request strings in POST requests, unlike GET . Parameter lines must be embedded in the request body in case of a POST request.

Use content-type : application/x-www-form-urlencoded

and in request-body use username=azerty&test=test

You should see the parameters in params inside the controller.

enter image description here

You should be able to see params : [age:25, name:Hamila, action:editProfile, controller:userWebService]

Did I make you look younger in the test? :)

+4
source

Source: https://habr.com/ru/post/1480959/


All Articles