Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:54:12+00:00 2026-05-27T01:54:12+00:00

I tried to run this perl5 program: #!/usr/bin/env perl use strict; use warnings; use

  • 0

I tried to run this perl5 program:

 #!/usr/bin/env perl                                                             

use strict;                                                                     
use warnings;                                                                   
use LWP;                                                                        

my $ua = LWP::UserAgent->new('Mozilla');                                        
$ua->credentials("test.server.com:39272", "realm-name", 'user_name', 'some_pass');                       
my $res = $ua->get('http://test.server.com:39272/');                  

print $res->content;

On other hand I have HTTP::Daemon:

#!/usr/bin/env perl                                                                                       

use strict;                                                                     
use warnings;                                                                   

use HTTP::Daemon;                                                               

my $hd = HTTP::Daemon->new or die;                                              

print "Contact URL: ", $hd->url, "\n";                                          
while (my $hc = $hd->accept) {                                                  
  while (my $hr = $hc->get_request) {                                           
    if ($hr->method eq 'GET') {                                                 
      print $hr->as_string, "\n";                                               
    }                                                                           
  }                                                                             
  $hc->close;                                                                   
  undef($hc);                                                                   
}    

And it just prints:

Contact URL: http://test.server.com:39272/
GET / HTTP/1.1
Connection: TE, close
Host: test.server.com:39272
TE: deflate,gzip;q=0.3
User-Agent: libwww-perl/6.03

So I see that LWP::UserAgent don’t send HTTP Basic auth, but I don’t know why.

I seen some post on this web site, but they have this same basic code, and it doesn’t
work…

If I use HTTP::Request then it works:

my $req = GET 'http://test.server.com:39272/';                        
$req->authorization_basic('my_id', 'my_pass');                                  
my $res = $ua->request($req);

Outputs:

GET / HTTP/1.1
Connection: TE, close
Authorization: Basic bXlfaWQ6bXlfcGFzcw==
Host: test.server.com:39272
TE: deflate,gzip;q=0.3
User-Agent: libwww-perl/6.03

Did I done something wrong before?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:54:13+00:00Added an answer on May 27, 2026 at 1:54 am

    LWP will only send the credentials for a realm if the server has told it that it’s trying to access that realm. A particular user may only be able to access particular realms or have different passwords for different realms. LWP doesn’t know which one to pick out of its credentials without the realm. Additionally, LWP isn’t going to use the data you store in the credentials unless it’s been challenged. You’re not doing that.

    If you supply the credentials directly by specifying the Authorization header, you do no realm checking. You can always send any header you like if you set it explicitly yourself, so it’s not surprising that you see it.

    You just need a better test server:

    use strict;                                                                     
    use warnings;                                                                   
    
    use HTTP::Daemon;                                                               
    use HTTP::Status;
    
    my $server = HTTP::Daemon->new or die;                                              
    
    print "Contact URL: ", $server->url, "\n";                                          
    while (my $connection = $server->accept) {                                                  
        while (my $request = $connection->get_request) {                                           
            print $request->as_string;
            unless( $request->header( 'Authorization' ) ) {                                                 
                $connection->send_response( make_challenge() )                                               
                }
            else {
                $connection->send_response( make_response() )                                               
                }   
            }                                                                             
        $connection->close;                                                                   
        }  
    
    sub make_challenge {
        my $response = HTTP::Response->new( 
            401 => 'Authorization Required',
            [ 'WWW-Authenticate' => 'Basic realm="Buster"' ],
             );
        }
    
    sub make_response {
        my $response = HTTP::Response->new( 
            200 => 'Huzzah!',
            [ 'Content-type' => 'text/plain' ],
             );
    
        $response->message( 'Huzzah!' );
        }
    

    When you run your client once, there should be two requests:

    GET / HTTP/1.1
    Connection: TE, close
    Host: macpro.local:52902
    TE: deflate,gzip;q=0.3
    User-Agent: libwww-perl/6.02
    
    GET / HTTP/1.1
    Connection: TE, close
    Authorization: Basic dXNlcl9uYW1lOnNvbWVfcGFzcw==
    Host: macpro.local:52902
    TE: deflate,gzip;q=0.3
    User-Agent: libwww-perl/6.02
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#!/usr/bin/env perl use warnings; use strict; use 5.012; use IPC::System::Simple qw(system); system( 'xterm', '-geometry',
When I run this code the selected item is not visible. I've already tried
How do I run this command with subprocess? I tried: proc = subprocess.Popen( '''ECHO
Error I tried this page to run on local, it is running perfectly fine
I downloaded HTTP::Daemon::SSL for Strawberry Perl 5.10 from CPAN and ran this example: use
I need to run a bash script and a perl program in detached background
I want to run some commands via a remote program. I've tried it using
I typically run my program with: perl -e 'print Ax200' | ./vuln_prog The stdin
Not sure if this is a Perl or Oracle issue. I'm new to both.
I have tryed to run this code in my console: script/plugin install git://github.com/apotonick/cells.git ...but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.