I have a script which log on to a secure website, but it's always
failed. I mean, It can't log in. For HTTPS request, I'm using
Crypt::SSLeay 0.49. I really appreciate it if someone could give me
advice on this, like the complete requirements for authentication
against a secure website from perl.

Below is my code:

#!/usr/bin/perl -w

#$|++;

use LWP;
use LWP::Debug '+'; # debug mode active
use URI::URL;
use HTTP::Cookies::Mozilla;
use HTTP::Request;
use HTTP::Request::Common;
use HTTP::Headers;
use strict;

$ENV{HTTPS_VERSION} = 23;
$ENV{HTTPS_DEBUG} = 8;
$ENV{HTTPS_CERT_FILE} = 'Crypt-SSLeay-0.49/certs/notacacert.pem';
$ENV{HTTPS_KEY_FILE} = 'Crypt-SSLeay-0.49/certs/notacakeynopass.pem';
$ENV{HTTPS_CA_FILE} = '/usr/share/ssl/certs/ca-bundle.crt';
$ENV{HTTPS_CA_DIR} = '/usr/share/ssl/certs';

my($statement_URL,$hdr,$server_response,$redirect_location);

$statement_URL="https://some.secure.site/loc/thefile.dll";;
$hdr="param1=val1&param2=val2";

$server_response=&browse($statement_URL,$hdr,'POST','login');     ##
 Fire the URL
$server_response=~ /Location:\s+(.*)\n/;
$redirect_location=$1;

#print $server_response;

sub browse(){
   my($statement_URL,$hdr,$method,$action)[EMAIL PROTECTED];

my($content_type,$response);

$content_type = "application/x-www-form-urlencoded";

my($ua) = new LWP::UserAgent;

   $ua->agent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1)");
   push @{ $ua->requests_redirectable }, 'POST';

   my($cookie) = new HTTP::Cookies::Mozilla(File =>
'/my/cookies/loc/cookies.txt', autosave => 1, ignore_discard => 1);

   my($headers) = new HTTP::Headers('Content-Type' => $content_type,
'Date' => HTTP::Date::time2str(time), 'Accept' => 'text/html');

   my($url)= new URI::URL($statement_URL);
   my($request)= new HTTP::Request($method, $url, $headers, $hdr);

print "\n\nprocessing URL: ".$url."\n\n";

   $request->authorization_basic('user', 'pwd');
   $ua->cookie_jar($cookie);
   $cookie->add_cookie_header($request);
   $response= $ua->request($request);
   $cookie->extract_cookies($response);

my($reply);

   if ($response->is_success){
       $reply=$response->content;
   } else {
       $reply=$response->error_as_HTML();
   }
   return $reply;
}

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail




Reply via email to