0

I'm trying to connect to a server with LWP::UserAgent. I have succeeded to do anonymous searches with LWP::UserAgent on that same server, but now I have to "secret" stuff and that requires to use authentication on that server. I have used the code:

my $ua = LWP::UserAgent->new;
$ua->default_header('Content-Type'  => "application/x-www-form-urlencoded");
$ua->default_header('Authorization' => "Basic ".$Authent);
my $resp  = $ua->post($uri);

The server reponds: error 400, Required param: grant_type

So, how do I set the grand type parameter with LWP? I have not found any page concerning the grand type problem.

I have tried also:

$ua->default_header('grant_type'    => "client_credentials");

and

my $resp  = $ua->post($uri, grant_type => "client_credentials");

All three gives exactly the same error message. I have no idea how to get things work.

TeeVee
  • 21
  • 1
  • https://metacpan.org/pod/LWP::UserAgent#ua-credentials-netloc-realm – mpapec Oct 23 '14 at 11:05
  • Thanks for fast respond. I have no idea, how to use that. The server does not use user id and password. It uses authorization on header to verify user rights. That was given on my code. The problem is on grant_type, which must be changed. – TeeVee Oct 23 '14 at 11:34

1 Answers1

2

TA-DAA! I found an answer.

The grant_type is not header stuff, it belongs to body. So, the working way to do this is:

$ua->default_header('Content-Type'  => "application/x-www-form-urlencoded");
$ua->default_header('Authorization' => "Basic ".$Authent);
my $resp  = $ua->post($uri, Content => ['grant_type' =>  "client_credentials"]);

Thanks anyway!

TeeVee
  • 21
  • 1