Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


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.


In reply to REST::Client does not provide any output by slayedbylucifer

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (3)
    As of 2021-01-24 06:30 GMT
    Find Nodes?
      Voting Booth?