0

I want to redirect user by post request to some server.

I have initial form, which is filled by user, and then I want to modify params, add extra ones, and then redirect user to final destination.

Initially I have tried to work via redirect method. But it make's GET request.

Then I used

response.status = 307
response.addHeader("Location", response.encodeRedirectURL("https://…"))

Before that piece of code I used

params.someParam = "some_info"

It looks like I modified local copy of params map and it didn't attach to my request.

I see in browser console, that code 307 makes redirect work, but request contains only old params.

So my question is: "Is there any way to add/modify post params before redirect?"

Seagull
  • 13,484
  • 2
  • 33
  • 45

1 Answers1

1

You have to encode them in the url

redirect "/newUrl?${params.toQueryString()}"

in your case

response.addHeader("Location", 
    response.encodeRedirectURL("https://…?${params.toQueryString()}"))
musketyr
  • 808
  • 5
  • 16
  • Thanks, It's work! It looks, like it doesn't make that params at request body. May I ask some details here? Is there any difference between query params and params in request body? May it be, that server expect only body-like params? And what should it do with duplicates, when I modified smth, and new vesion is in quert string, when old in body? – Seagull Jun 04 '14 at 14:40
  • the params map in groovlets and gtpl templates are just regular hash map which is read once at the beginning of the request where initially all the values are of type String (if only one value is passed) or String[] (if there are duplicates in the URL params. see the note how you can safely cast these values to different types here: http://gaelyk.appspot.com/tutorial/views-and-controllers – musketyr Jun 05 '14 at 09:43