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_authorizat
ion_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->header
s_as_strin
g;
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:portLWP::UserAgent::request: ()
LWP::UserAgent::simple_req
uest: GET
https://www.site.com/page.nsfLWP::UserAgent::_need_prox
y: Proxied to
http://proxy:portLWP::Protocol::
http::request: ()
LWP::Protocol::
http::request: GET
https://www.site.com/page.nsf HTTP/1.0
Host:
www.site.comProxy-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