Update:
I figured it out and got a 200 OK response.
I added the following lines.
my $auth_token = "code";
$ua->default_header( "Authorization" => "Bearer $auth_token");
Guys,
It's my first time I will attempt to use perl to access an API for information. I was looking around and found this code which I kind of modified for my use. The issue is that I am unsure where to include the token key required to make the request. I'm not sure if I need to include it in the http request itself, but if so, how? The response I'm currently getting is 400 Bad Request. I appreciate any help.
The credentials have been ommited for security reasons.
#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::UserAgent;
require HTTP::Cookies;
my $ua = new LWP::UserAgent;
my $cookie_jar = HTTP::Cookies->new( file => 'cookies_lwp.txt', autosa
+ve => 1, ignore_discard => 1 ); # A cookie file is needed to store th
+e security keys.
$ua->cookie_jar($cookie_jar);
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
$ua->default_header( "Accept" =>"application/json" );
$ua->default_header( "Content-Type" => "application/json");
my $netloc="host";
my $realm="realm name";
my $user="username";
my $pass="password";
$ua->credentials( $netloc, $realm, $user, $pass);
$ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00);
my $req = new HTTP::Request('GET','https://host/api/v2/devices/00:04:5
+6:22:51:32/performance/?start_time=2022-02-15T10:00:00&stop_time=2022
+-02-16T10:00:00');
my $res = $ua->request($req);
print $res->code, "\n";
print $res->message;
use Data::Dumper;
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.