Reading HTTP Request parameters

Hello
I’ve a client which send this request to a mongrel HTTPHandler :

res=Net::HTTP.post_form(URI.parse(‘http://localhost:3000/test’),{“a”=>1,“b”=>2})

But in the handler I can’t read the parameters one by one, I can read
the entire String only :
class Serveur
class MyHandler < Mongrel::HttpHandler
def process(req, resp)

@params=req.params
@params.http_body

end
end

end

@params.http_body give me :
a=1&b=2 which is a string

I would like a code which return me 1 for something[:a] and 2 for
something[:b]…
thanks

HttpRequest.query_parse(@params.http_body)

http://mongrel.rubyforge.org/rdoc/classes/Mongrel/HttpRequest.html#M000126

Eden Li wrote:

HttpRequest.query_parse(@params.http_body)

http://mongrel.rubyforge.org/rdoc/classes/Mongrel/HttpRequest.html#M000126

:slight_smile:
that’s just what I’m searching (I tried it with a wrong syntax :
req.query_parse and it didn’t work…)

thanks

On Mon, 14 Jan 2008 15:39:25 +0100
“Abir B.” [email protected] wrote:

Eden Li wrote:

HttpRequest.query_parse(@params.http_body)

http://mongrel.rubyforge.org/rdoc/classes/Mongrel/HttpRequest.html#M000126

:slight_smile:
that’s just what I’m searching (I tried it with a wrong syntax :
req.query_parse and it didn’t work…)

Yes, sadly you have to do this yourself because all the frameworks have
their own interpretation of how the query parameters are parsed.


Zed A. Shaw