mcgilljd
asked on
perl script to view https page that is password protected
I have this script from adam314 to view a https page but the page requires a userid and password, which i have. How can I change the script to insert userid and password?
use Net::SSLeay qw(get_https);
($page) = get_https('www.bacus.pt', 443, '/');
die "No page\n" unless $page;
open(OUT,">page.txt") or die "output: $!\n";
print OUT $page;
close(OUT);
use Net::SSLeay qw(get_https);
($page) = get_https('www.bacus.pt', 443, '/');
die "No page\n" unless $page;
open(OUT,">page.txt") or die "output: $!\n";
print OUT $page;
close(OUT);
How does it ask for a username/password when you go to the page with a browser?
ASKER
yes when I go to page with browser it asks for user name, password
Do you get a web page asking for user/pass? Or a window pop-up asking for user/pass?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it is a popup window
That means it uses basic authentication.
ASKER
Tintin, I tried to use your code.
It doesn't give an error, but it doesn't print to page.txt either
use LWP::UserAgent;
my $urlhome ="https://website.com/WebUI/Servlet/Reviewer?axn=review";
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET => $urlhome) or die "no page\n";
$req->authorization_basic( 'myuserID' , 'mypassword');
open FILE, ">C:\Desktop\prices.txt" or die "Can not open page.txt $!\n";
print FILE $ua->request($req)->as_str ing;
close FILE;
It doesn't give an error, but it doesn't print to page.txt either
use LWP::UserAgent;
my $urlhome ="https://website.com/WebUI/Servlet/Reviewer?axn=review";
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET => $urlhome) or die "no page\n";
$req->authorization_basic(
open FILE, ">C:\Desktop\prices.txt" or die "Can not open page.txt $!\n";
print FILE $ua->request($req)->as_str
close FILE;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
C:\>Perl C:\PerlScripts\login3.pl
501 Protocol scheme 'https' is not supported (Crypt::SSLeay not installed) at C:
\PerlScripts\interactivelo gin3.pl line 11.
I will install Crypt::SSLeay and try again later
501 Protocol scheme 'https' is not supported (Crypt::SSLeay not installed) at C:
\PerlScripts\interactivelo
I will install Crypt::SSLeay and try again later
ASKER
Ok i installed crypt::SSLeay and added line
use Crypt::SSLeay ;
Now I get
401 Unauthorized at line 12
But if I use browser to go to page it works.
use Crypt::SSLeay ;
Now I get
401 Unauthorized at line 12
But if I use browser to go to page it works.
Possibly the site you are trying to connect to requires cookies or looks at the user agent string.
Try adding
$ua->agent("Mozilla/4.0");
and see if it makes a difference.
Try adding
$ua->agent("Mozilla/4.0");
and see if it makes a difference.
You shouldn't need to "use" Crypt::SSLeay - it will be used by the other modules if needed.
It sounds as if you've provided incorrect username and/or password (and/or netloc and/or realm if using the ->credentials function)
Are you sure you have these correct? It is likely case sensitive.
It sounds as if you've provided incorrect username and/or password (and/or netloc and/or realm if using the ->credentials function)
Are you sure you have these correct? It is likely case sensitive.
ASKER
added
$ua->agent("Mozilla/4.0");
no change, i will have to try later
$ua->agent("Mozilla/4.0");
no change, i will have to try later
ASKER
I tried using credentials method here is my script
use LWP::UserAgent;
my $urlhome ="https://website.com/WebUI/Servlet/Reviewer?axn=review";
my $userid ="MyID";
my $password ="P@ssword";
my $netloc ="111.222.333.444:80";
my $realm ="REALM";
my $outfile ="C:\Documents and Settings\Desktop\interacti veprices.t xt";
$ua = LWP::UserAgent->new;
$ua->credentials( $netloc, $realm, $userid, $password );
$req = HTTP::Request->new(GET => $urlhome) or die "no page\n";
$res = $ua->request($req);
die $res->status_line unless $res->is_success;
open (OUTFILE, ">$outfile") or die "Can not open prices.txt $!\n";
print OUTFILE $res->decoded_content;
close OUTFILE;
I still get 401 unauthorized
my password and username are correct but I am not sure exactly what to use for "realm"
use LWP::UserAgent;
my $urlhome ="https://website.com/WebUI/Servlet/Reviewer?axn=review";
my $userid ="MyID";
my $password ="P@ssword";
my $netloc ="111.222.333.444:80";
my $realm ="REALM";
my $outfile ="C:\Documents and Settings\Desktop\interacti
$ua = LWP::UserAgent->new;
$ua->credentials( $netloc, $realm, $userid, $password );
$req = HTTP::Request->new(GET => $urlhome) or die "no page\n";
$res = $ua->request($req);
die $res->status_line unless $res->is_success;
open (OUTFILE, ">$outfile") or die "Can not open prices.txt $!\n";
print OUTFILE $res->decoded_content;
close OUTFILE;
I still get 401 unauthorized
my password and username are correct but I am not sure exactly what to use for "realm"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.