Search code examples
perlasynchronouscpanpoe

User authentication using POE::Component::Client::HTTP


I am trying to find a module in perl poe which can do user authentication while making a HTTP request.

HTTP request should be non-blocking

or

How should I use poe::component::client:http to do user authentication by providing username , password details?


Solution

  • You can pass a HTTP::Request object to POE::Component::Client::HTTP. Basic Auth is solved with a header, and can be sent as a header:

     use strict;
     use warnings;
     use MIME::Base64;
     use HTTP::Request;
    
     my $username = 'username';
     my $password = 'password';
     my $auth = 'Basic ' . MIME::Base64::encode($username . ':' . $password);
    
     my $request = HTTP::Request->new(GET => 'http://www.example/',
        [Authorization => $auth]);
    

    And then just pass the $request to $poe_kernel->post as in the documentation.