Hi. When I open the postman application and request a token manually, I get the following in the console.
POST https://xxx.xx.xx.xx/api/v2/access/token 200 62 ms Warning: Self signed certificate POST /api/v2/access/token HTTP/1.1 Content-Type: application/x-www-form-urlencoded Authorization: Basic bGJLN0dLaGNmVTM2MkxNbjpzOUtKRXR0UVBHeGIyTkxkcEpMM +3hHbmlLN0MwaUk= User-Agent: PostmanRuntime/7.29.0 Accept: */* Cache-Control: no-cache Postman-Token: 1979ab3e-0607-4544-a239-05d37cb2dd87 Host: 172.20.19.21 Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Length: 29 grant_type=client_credentials HTTP/1.1 200 OK Server: nginx Date: Sat, 05 Mar 2022 07:31:30 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive ETag: W/"63-lVO9g4PVOvVMxmtOQ57cFQLhFck" Strict-Transport-Security: max-age=31536000; includeSubDomains Content-Encoding: gzip {"access_token":"16f7a07cc25b2cf3618b8286180eb264744e145f","expires_in +":3600,"token_type":"bearer"}
I'm trying to use the following perl script to request the token. But I get a Bad Request error.
#!/usr/bin/perl -w use strict; use warnings; use LWP::UserAgent; my $netloc = "xxx.xx.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( "Authorization" => "Basic bGJLN0dLaGNmVTM2MkxNbjp +zOUtKRXR0UVBHeGIyTkxkcEpMM3hHbmlLN0MwaUk="); $ua->default_header( "Accept" => "*/*" ); $ua->default_header( "Content-Type" => "application/x-www-form-urlenco +ded"); $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( POST => $query); my $resp = $ua->request($req); if ($resp->is_success) { my $output = $resp->decoded_content; print $output."\n"; } else { print $resp->as_string(); }
I get this reponse...
[user@localhost wifi]$ ./wifi-api-test-token.pl HTTP/1.1 400 Bad Request Connection: close Date: Sat, 05 Mar 2022 07:34:43 GMT ETag: W/"1b-WJVp2bnCdBNm40JHvp3t41llPJs" Server: nginx Content-Length: 27 Content-Type: application/json; charset=utf-8 Client-Date: Sat, 05 Mar 2022 07:35:10 GMT Client-Peer: 172.20.19.21:443 Client-Response-Num: 1 Client-SSL-Cert-Issuer: /O=Cambium Networks Ltd. Client-SSL-Cert-Subject: /O=Cambium Networks Ltd. Client-SSL-Cipher: ECDHE-RSA-AES128-GCM-SHA256 Client-SSL-Socket-Class: IO::Socket::SSL Client-SSL-Version: TLSv1_2 Client-SSL-Warning: Peer certificate not verified Strict-Transport-Security: max-age=31536000; includeSubDomains {"error":"invalid_request"}

In reply to Re^2: Getting an Access Token by PerlMonger79
in thread Solved: Getting an Access Token by PerlMonger79

Title:
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, 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:
    & &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.