Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Restful Client Query

by beckmanel (Initiate)
on Jun 28, 2016 at 16:57 UTC ( #1166807=perlquestion: print w/replies, xml ) Need Help??

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

Problem implementing a relatively simple restful client query, that I have already implemented in curl. A request for device information from a cisco ISE server.

#!/usr/bin/perl use warnings; use REST::Client; use LWP::UserAgent; use JSON; use MIME::Base64; use Data::Dumper; $ENV{HTTPS_VERSION} = 3; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; ######################################################## # This works in the shell ######################################################## #curl -k 'https://<myuser>:<mypassword>@<myhost>/webacs/api/v1/data/De +vices' my $host = 'https://<myhost>'; my $user = '<myuser>'; my $pwd = '<mypassword>'; my $client = REST::Client->new(host => $host); my $encoded_auth = encode_base64("$user:$pwd", ''); $client->GET("/webacs/api/v1/data/Devices", {'Authorization' => "Basic $encoded_auth", 'Accept' => 'application/json'}); print 'Response: ' . $client->responseContent() . "\n"; print 'Response status: ' . $client->responseCode() . "\n"; foreach ( $client->responseHeaders() ) { print 'Header: ' . $_ . '=' . $client->responseHeader($_) . "\n"; } __END__ Response: Can't connect to <myhost>:443 LWP::Protocol::https::Socket: SSL connect attempt failed with unknown +errorerror:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert h +andshake failure at /usr/lib/perl5/site_perl/5.10.0/LWP/Protocol/http +.pm line 47. Response status: 500 Header: Content-Type=text/plain Header: Client-Date=Tue, 28 Jun 2016 13:56:58 GMT Header: Client-Warning=Internal response
Thank You !!

Replies are listed 'Best First'.
Re: Restful Client Query
by morgon (Priest) on Jun 28, 2016 at 21:17 UTC
    Look at your error message. It says: "handshake failure".

    So the problem is establishing the SSL-connection.

    Could be a certficate problem or the client and the server can for whatever reason not agree on which cipher to use etc.

Re: Restful Client Query
by perlfan (Curate) on Jun 28, 2016 at 20:08 UTC
    Error codes of 5xx indicate server error, take a look at this list of HTTP status codes.

    Now more to the point about the failure to establish an SSL connect. Since you're issuing a GET, you can easily check this url in your browser. If it works in your browser, then it might be your client.

    Each browser has at least 1 good REST client dashboard, I'd use the one for your browser of choice. IMO, it's enhances the script writing experience by giving you a little more control to tinker.
Re: Restful Client Query
by NetWallah (Canon) on Jun 28, 2016 at 18:07 UTC
    Response status: 500
    This indicates a SERVER side error - you will need to look at the web server (apache/tomcat etc) logs to see what the problem was.

            This is not an optical illusion, it just looks like one.

      *cough* Header: Client-Warning=Internal response
Re: Restful Client Query
by NetWallah (Canon) on Jun 28, 2016 at 21:39 UTC
    Looks like I goofed up my first response: I did not notice "Header: Client-Warning=Internal response".

    I am not an expert on REST, but all my successful tests have used POST for the initial authorization request, so I suggest you try that, instead of GET.

            This is not an optical illusion, it just looks like one.

      If implemented halfway consistently, using the wrong HTTP method (i.e., GET when a POST, etc is required) should result in a 404.

        You mean 405?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1166807]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2019-10-14 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?