Thank you to everyone for helping me out. I might be mistaken, but I have an impression that there are 2 kind of authorizations.
1) It looks like in example below: http://www.buddhism-dict.net/cgi-bin/xpr-dealt.pl There is an example for perl program here: http://www.rosettacode.org/rosettacode/w/index.php?title=HTTPS_request_with_authentication 2) When there is a login screen where a user needs to supply login/password. It's similar to PayPal login screen. I'm looking solutions for the second type of authorization. I wrote a program, based on examples received from this post. It doesn't work. I tried to login into a regular, not https site ... but failed. I don't have publicly available site and guests login to share with the community ... unfortunately. The task seems straightforward: 1. Posting login/password information on proper fields of the form. 2. Requesting needed page. It looks like POST works OK (Block 1). In block #2 I'm getting back login screen and saving into file for further review. It looks like login/password information is correct when I looked source code for this HTML. Block #3 returns me HTML page but not that I expecting. It returns the page that normally comes when a user tried to get this page directly, without authorization or with invalid session object. Does anybody have suggestion what I'm doing wrong and how to fix it? Thank you #---------------------------------------------------------- code start use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common qw(GET POST); use strict; my $url='http://a_site/login.jsp'; my $ua = LWP::UserAgent->new(); $ua->agent('Mozilla/5.0'); my $cookie_jar = HTTP::Cookies->new(); my @fld_val =(); my @fld_name =(); $fld_name[0]='user_name'; $fld_val[0]= 'Tom'; $fld_name[1]='password'; $fld_val[1]= 'pass_for_tom'; my $data = [ $fld_name[0] => $fld_val[0], $fld_name[1] => $fld_val[1] ]; #----------------- Block 1 ------------------- my $response = $ua->request(POST($url, Content => $data ) ); if ($response->is_error ) { die "Response ERROR"; }; $cookie_jar->extract_cookies($response); $cookie_jar->save('cookie_01.txt'); #----- #----------------- Block 2 ------------------- # Still login screen my $ct = $response->content; my $file_name='U:\Perl\Data\Misc\log_01.html'; open(FILE_LOG, ">$file_name") || die"Can not open file $file_name to write"; print FILE_LOG "$ct"; close(FILE_LOG); #--- #----------------- Block 3 ------------------- # Below is a page I need to get $url = 'http://a_site/main.jsp'; my $request = new HTTP::Request GET => $url; $response = $ua->request($request); my $html_page_received=''; $html_page_received = $response->content; $file_name='U:\Perl\Data\Misc\target_01.html'; open(FILE_TRG, ">$file_name") || die"Can not open file $file_name to write"; print FILE_TRG "$html_page_received"; close(FILE_TRG); #---------------------------------------------------------- code end On Wed, Mar 5, 2008 at 10:59 AM, Andrej Sokurov <[EMAIL PROTECTED]> wrote: > Hello everyone: > > I need to write a program that would fetch an HTML page from a secure site > that requires authorization. > When a human it usually done in following sequence: > 1. Get login screen (https) > 2. Supply login/password > 3. Get needed HTML page (https) > 4. Logout > > Doing similar thing without required authorization is very simple and > straightforward procedure: > > my($request) = new HTTP::Request GET => $url; > my($ua) = new LWP::UserAgent; > my($response) = $ua->request($request); > my($html_page_received)=$response->content; > > However, getting through secure site that requires authorization is not > clear for me. > Could somebody point me in a right direction? It would be the best, if > somebody gives me an example of such program > > Thank you. >
_______________________________________________ Perl-Win32-Web mailing list Perl-Win32-Web@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs