Advertisement

02.24.2002 at 12:59PM PST, ID: 20270472
[x]
Attachment Details

lwp -> password proxy -> https (ActivePerl)

Asked by red5 in Perl Programming Language

Tags: lwp, proxy, password, https

I want to write a script that checks a webpage for updates.  This task is complicated by these factors:
(NOTE: I'm running ActivePerl 5.005_03 on win2k)

1) I'm behind a proxy that requires username/password
2) The webpage I'm checking is https (note the 's')
3) I have to enter another username/password in a form
   on that webpage
4) I think that webpage uses a short-term cookie after
   I enter the second username/password.

Here's where I am:

1) I think I got this solved - I can get webpages like
   www.yahoo.com (NOTE: I'm NOT setting the username and
   password in environment variables)
2) I used ActiveState's ppm to install Crypt-SSLeay.
3) No progress.
4) I hope I don't have to deal with this - I should be
   able to just enter the username/password from the
   script everytime, right?

Here is the code I use to get regular webpages:
(NOTE: I didn't list the actual website and proxy as I
       don't want the specifics on an open website...)

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

my $proxy = "http://proxy:port";
my $url = "https://www.site.com/page.nsf";
my ($username, $password) = @ARGV;

my ($code, $desc, $headers, $body) =
  http_get( $url, $proxy, $username, $password );

print "CODE:\n$code\n";
print "DESC:\n$desc\n";
print "HEADERS:\n$headers\n";
print "BODY:\n$body\n";

exit;

sub http_get( ) {
 
  my ($path, $proxy, $username, $password) = @_;

# Create a User Agent object
  my $ua = new LWP::UserAgent;
  $ua->agent("hcat/1.0");
 
# If proxy server specified, define it in the User Agent object
  if (defined $proxy) {
    my $url = new URI::URL $path;
    my $scheme = $url->scheme;
    $ua->proxy($scheme, $proxy);
  }
 
# Ask the User Agent object to request a URL.
# Results go into the response object (HTTP::Reponse).
 
  my $request = new HTTP::Request("GET", $path);
  $request->proxy_authorization_basic($username, $password);
  my $response = $ua->request($request);
 
# Parse/convert the response object for "easier reading"
 
  my $code=$response->code;
  my $desc = HTTP::Status::status_message($code);
  my $headers=$response->headers_as_string;
 
  my $body =  $response->content;
  $body =  $response->error_as_HTML if ($response->is_error);
 
  return ($code, $desc, $headers, $body);
}

----------------------------------------------

I *thought* this would still work - triggering off the
https in the URL and load the SSL stuff, but maybe not.

Here is the output:

LWP::UserAgent::new: ()
LWP::UserAgent::proxy: https, http://proxy:port
LWP::UserAgent::request: ()
LWP::UserAgent::simple_request: GET https://www.site.com/page.nsf
LWP::UserAgent::_need_proxy: Proxied to http://proxy:port
LWP::Protocol::http::request: ()
LWP::Protocol::http::request: GET https://www.site.com/page.nsf HTTP/1.0
Host: www.site.com
Proxy-Authorization: Basic dzE2OTU5OlgyMnNldHVw
User-Agent: hcat/1.0

LWP::Protocol::http::request: reading response
LWP::Protocol::http::request: HTTP/1.0 403 Forbidden
Date: Sun, 24 Feb 2002 20:42:54 GMT
Content-Length: 1360
Content-Type: text/html
Server: NetCache (NetApp/5.2.1D8)
Connection: keep-alive

It goes on to give a proxy "Access Denied" page, *BUT*
I can get to this site from Internet Explorer, so I know
the proxy will allow it - I just have to figure out how
to get PERL to do the same thing IE is doing.

Any help would be appreciated.Start Free Trial
 
 
[+][-]02.28.2002 at 02:33AM PST, ID: 6831405

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: lwp, proxy, password, https
Sign Up Now!
Solution Provided By: vermeylen
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.03.2003 at 02:13AM PDT, ID: 9483319

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32