Hi guys,
I am currently using Postman to manually generate an access token for my perl script to get data from an API, but it expires every hour. However, I would like to create a perl script to make the access token request and pass that token to my other script. With the sample code I'm using I get a 400 Bad Request message. Can you please help me and tell me if I'm missing a parameter? For security, I've ommited the credential values.
#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::UserAgent;
my $netloc = "xxx.xx.xx";
my $realm = "realm";
my $user = "usercode";
my $pass = "passcode";
my $ua = LWP::UserAgent->new();
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
$ua->default_header( "Accept" => "application/json" );
$ua->default_header( "Content-Type" => "application/json");
$ua->credentials( $netloc, $realm, $user, $pass);
$ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00);
my $query = "https://".$netloc."/api/v2/access/token";
my $req = HTTP::Request->new( GET => $query);
my $resp = $ua->request($req);
if ($resp->is_success) {
my $output = $resp->decoded_content;
print $output."\n";
}
else {
print STDERR $resp->status_line, "\n";
}
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.