[Kc] Perl LWP (libwww-perl) problems using a proxy that requires Authentication

Daryl Fallin darylvf at gmail.com
Wed Mar 25 10:23:33 PDT 2009


Hey KC Perl Mongers and CCCKC -

I am trying to retrieve scan result information from Qualys from inside a
corporate network that has a proxy that requires authentication.

There seems to be a problem with LWP and proxy settings as found in the
following links.

http://www.codecomments.com/archive233-2006-1-764165.html
http://groups.google.fi/group/perl.libwww/browse_thread/thread/aee0e06b1404387/e28d1e3670a21ad5?lnk=st&q=%22https+through+proxy+with+libwww%22&rnum=1#e28d1e3670a21ad5
http://rt.cpan.org/Public/Bug/Display.html?id=1894

But when I try the workarounds by using the environment variables for
http_proxy and/or https_proxy it still fails.

If anyone has seen this before or knows a quick fix, please let me know.  I
am tempted to just call wget which can authenticate to the proxy and pass
the Qualys credentials as well.

Here is my test code to just retrieve the scan_results from Qualys.

=========================
#!/usr/bin/perl

use strict;
$|++;

use LWP::UserAgent;
#use LWP::Debug qw(+);

my $username = 'qualys_user';
my $password = 'qualys_pass';
$ENV{HTTP_PROXY} = 'http://proxyuser:proxypass@192.168.1.1:8080';
$ENV{HTTPS_PROXY} = 'http://proxyuser:proxypass@192.168.1.1:8080';

my $ua = LWP::UserAgent->new;
# This script doesn't work with the below line uncommented or commented.
# I assume that if this is commented that LWP will use the environment
variables defined above.
#$ua->proxy(['http', 'https'], 'http://proxyuser:proxypass@192.168.1.1:8080
');


my $req = HTTP::Request->new(GET => 'https://$username:$password\@
qualysguard.qualys.com/msp/scan_report_list.php');
my $res = $ua->request($req);
if ($res->is_success) {
    print $res->as_string;
}
else {
    print "Failed: ", $res->status_line, "\n";
}
=========================

If I use the Environment variables I get the following message:

Failed: 500 Can't connect to qualysguard.qualys.com:443 (Timeout)

If I uncomment the line "$ua->proxy(['http', 'https'],
'http://proxyuser:proxypass@192.168.1.1:8080');"  I get this message:

Failed: 400 Bad Request
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/kc/attachments/20090325/1049be31/attachment.html>


More information about the kc mailing list