Richard Lawrence
2005-03-30 13:45:33 UTC
Hi all,
I'm trying to access https://www.nodeworks.com/ through a proxy which
requires a proxy username and password. The code I have is as follows:
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use Data::Dumper qw(Dumper);
# If they provide an argument, connect to https else http
my $url = "http://www.nodeworks.com";
$url = "https://www.nodeworks.com" if ($ARGV[0]);
print "Going to get $url\n";
my $ua = new LWP::UserAgent;
# According to Crypt::SSLeay:
# "Use of the HTTPS_PROXY environment variable in this way is
# similar to LWP::UserAgent->env_proxy() usage, but calling that
# method will likely override or break the Crypt::SSLeay support,
# so do not mix the two."
# so only define $ua->proxy when using http.
if ($url =~ /^https/i)
{
print "Using HTTPS proxy $ENV{HTTPS_PROXY}\n";
}
else
{
$ua->env_proxy();
print "Using HTTP proxy $ENV{HTTP_PROXY}\n";
}
$ua->timeout(15);
my $req = new HTTP::Request('HEAD', $url);
my $res = $ua->request($req);
print "Result is:\n";
print Dumper($res);
My environment variable for http_proxy is set up like so:
http_proxy=http://richard:***@10.10.200.44:8080/
HTTP_PROXY=http://richard:***@10.10.200.44:8080/
export ...all of the above...
and running the code above with no arguments produces the desired
result.
However, if I try the code above with an argument (so it trys https)
with the following environment variables:
https_proxy=http://richard:***@10.10.200.44:8080/
HTTPS_PROXY=http://richard:***@10.10.200.44:8080/
export ...all of the above...
or even:
https_proxy=http://10.10.200.44:8080/
HTTPS_PROXY=http://10.10.200.44:8080/
https_proxy_username=richard
HTTPS_PROXY_USERNAME=richard
https_proxy_password=mypassword
HTTPS_PROXY_PASSWORD=mypassword
export ...all of the above...
then I always get the following error:
$VAR1 = bless( {
'_content' => '500 Can\'t connect to www.nodeworks.com:443 (Bad service
\'8080/\')',
'_rc' => 500,
'_headers' => bless( {
'client-warning' => 'Internal response',
'client-date' => 'Wed, 30 Mar 2005 13:41:12 GMT',
'content-type' => 'text/plain'
}, 'HTTP::Headers' ),
'_msg' => 'Can\'t connect to www.nodeworks.com:443 (Bad service
\'8080/\')',
'_request' => bless( {
'_content' => '',
'_uri' => bless( do{\(my $o = 'https://www.nodeworks.com')},
'URI::https' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/5.803'
}, 'HTTP::Headers' ),
'_method' => 'HEAD'
}, 'HTTP::Request' )
}, 'HTTP::Response' );
Can anyone offer any suggestions?
Many thanks,
Richard
I'm trying to access https://www.nodeworks.com/ through a proxy which
requires a proxy username and password. The code I have is as follows:
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use Data::Dumper qw(Dumper);
# If they provide an argument, connect to https else http
my $url = "http://www.nodeworks.com";
$url = "https://www.nodeworks.com" if ($ARGV[0]);
print "Going to get $url\n";
my $ua = new LWP::UserAgent;
# According to Crypt::SSLeay:
# "Use of the HTTPS_PROXY environment variable in this way is
# similar to LWP::UserAgent->env_proxy() usage, but calling that
# method will likely override or break the Crypt::SSLeay support,
# so do not mix the two."
# so only define $ua->proxy when using http.
if ($url =~ /^https/i)
{
print "Using HTTPS proxy $ENV{HTTPS_PROXY}\n";
}
else
{
$ua->env_proxy();
print "Using HTTP proxy $ENV{HTTP_PROXY}\n";
}
$ua->timeout(15);
my $req = new HTTP::Request('HEAD', $url);
my $res = $ua->request($req);
print "Result is:\n";
print Dumper($res);
My environment variable for http_proxy is set up like so:
http_proxy=http://richard:***@10.10.200.44:8080/
HTTP_PROXY=http://richard:***@10.10.200.44:8080/
export ...all of the above...
and running the code above with no arguments produces the desired
result.
However, if I try the code above with an argument (so it trys https)
with the following environment variables:
https_proxy=http://richard:***@10.10.200.44:8080/
HTTPS_PROXY=http://richard:***@10.10.200.44:8080/
export ...all of the above...
or even:
https_proxy=http://10.10.200.44:8080/
HTTPS_PROXY=http://10.10.200.44:8080/
https_proxy_username=richard
HTTPS_PROXY_USERNAME=richard
https_proxy_password=mypassword
HTTPS_PROXY_PASSWORD=mypassword
export ...all of the above...
then I always get the following error:
$VAR1 = bless( {
'_content' => '500 Can\'t connect to www.nodeworks.com:443 (Bad service
\'8080/\')',
'_rc' => 500,
'_headers' => bless( {
'client-warning' => 'Internal response',
'client-date' => 'Wed, 30 Mar 2005 13:41:12 GMT',
'content-type' => 'text/plain'
}, 'HTTP::Headers' ),
'_msg' => 'Can\'t connect to www.nodeworks.com:443 (Bad service
\'8080/\')',
'_request' => bless( {
'_content' => '',
'_uri' => bless( do{\(my $o = 'https://www.nodeworks.com')},
'URI::https' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/5.803'
}, 'HTTP::Headers' ),
'_method' => 'HEAD'
}, 'HTTP::Request' )
}, 'HTTP::Response' );
Can anyone offer any suggestions?
Many thanks,
Richard