Perl REST::Client – POST method

I’m working on rewriting Redmine::API to remove Net::HTTP::Spore.

The simple replacement is to handle the request with REST::Client.

My first question was, how can I post params with that ? How can I do an equivalent to the “payload” of Net::HTTP::Spore ?

Well, after googling and trying stuff, here the result :

Here the client :

Here the server :

in ‘lib/’ :

in rc.yml :

And then to launch it :

The result is :

So you can encode params like you do with GET and pass it to the POST method without the interrogation mark “?”.

So for example :

REST::Client has an method to do that for you, but it is for the GET method, so you have to remove the interrogation mark ‘?’ :

You can also use URI

A very important header is to properly setup the content type :

{‘Content-type’ => ‘application/x-www-form-urlencoded’}

It indicate that you have encode your params in a certain way.

I hope this could help.


Short URL: