I have some controller (ExampleController
) that receives requests with content-type
application/x-www-form-urlencoded
.
I need to send all the request data to a different URL using POST
request. The data needs to be in the same order as received it.
Problem is that the content does not match because request.getParameterMap()
destroys the order of the data.
In ExampleController
:
def method(){
String s = request.reader.text //this is empty, need a way to read this text
Map<String, String[]> vars = request.getParameterMap() //it's not good for me because the map is unordered map
//but it full of data
}
which does not work.
I need something like:
byte[] data = request.getRequestData()
wr.write(data)
btw i've tried:
InputStream = request.getInputStream()
byte [] bytes = inputStream.getBytes()
I've also tried
String s = request.reader.text
but the string is empty. I think the main problem is that grails mechanism reads the input stream before the controller even starts and place the data in the parameters hashMap. is there a way to undo it?
Any help will be greatly appreciated
Try using request.reader.text instead.
def result = request.reader.text.split('&').inject([:]) { map, token ->
token.split('=').with { map[it[0]] = it[1] }
map
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With