Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LWP, HTTPS and cookies

Status
Not open for further replies.

plotzer

Programmer
Aug 28, 2001
35
0
0
US
Hello,

I am trying to pull some info from a HTTPS website. I am using LWP with the Crypt-SSLeay module for https support. I am able to connect to the site, but I am returned a page saying my browser is not cookie enabled and the page I want is not accessible. Is it possible to access such data outside of a browser via perl and fake the server into thinking you have cookies enabled. I know there are some modules within in LWP for cookie handling, but before I spend alot of time attempting this I want to make sure it is possible to do what I want to do. My code is as follows:

#use strict;
#use warnings;

use LWP::UserAgent;

my $uri = 'my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $uri);
my $res = $ua->request($req);

if ($res->is_success) {

print $res->as_string;

} else {

print "Failed to GET '$uri': ", $res->status_line, "\n";
}


If I enter the url in my browser, the correct page is returned.

Thanks in advance.
 
I've still been unable to solve the cookie thing using perl. I've been attempting to use the HTTP::Cookies::Netscape module to accomplish this but the site I am trying to access still does not recognize cookies as being enabled. I've included my code below to see if anyone has any clues what I might be doing wrong.

Thanks



use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Cookies::Netscape;

my $url = "my $browser = LWP::UserAgent->new;
open (FILEHANDLE, ">comcast_test.htm") or die "no such file";

$browser->cookie_jar( HTTP::Cookies::Netscape->new(
'file' => 'C:\Documents and Settings\administrator\cookies.txt',
'autosave' => 1
));


my $response = $browser->get($url,'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206 Firefox/0.8');

print FILEHANDLE $response->content;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top