slayedbylucifer has asked for the wisdom of the Perl Monks concerning the following question:


I am working with REST::Client. I just want to login to a REST interface and get the authentication token.

Here is my curl command:

curl -i -k -H "Accept:application/*+xml;version=1.5" -u "username@syst +em:password" -X post https://something/api/sessions

And here is the curl output:

HTTP/1.1 200 OK Date: Mon, 17 Jun 2013 08:19:59 GMT x-authorization: qQHvPTvOa49l8EyuWSwmoDzMn8nVHWDbFUP+tC9RyMk= Set-Cookie: token=qQHvPTvOa49l8EyuWSwmoDzMn8nVHWDbFUP+tC9RyMk=; Secure +; Path=/ Content-Type: application/session+xml;version=1.5 Date: Mon, 17 Jun 2013 08:20:00 GMT Content-Length: 1055

I have removed my company specific info from above output. Anyway, the command works fine which means I have the information that is needed to get the authentication token.

I am trying to achieve the same via perl code.

Here is my code:

#!usr/bin/perl -w use strict; use REST::Client; use MIME::Base64; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; ### to ignore the SSL my $username = 'username@system'; my $password = 'password'; my $url = "https://something/api/sessions"; my $client = REST::Client->new(); my $headers = { "Accept" => "application/*+xml;version=1.5", "Authorization" => 'Basic ' . encode_base64($username . + ':' . $password), }; $client->POST($url,$headers); print $client->responseContent();

Now my script does not print anything. It exits with nothing being printed on the screen. Also, if I change the password to the wrong one, it still exits without printing anything. I suspect the “POST” line in my code is not right but I cannot correct it. I tried various different combination of POST statement but none worked.

Could you tell me what am I missing here? It should at least print some error message when I provide wrong password but it is not doing so either.