l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 20: Web Application Hacking: How to Make and Break Security on the Web
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2003 Jul 02 08:22

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Getting https with perl
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Getting https with perl



--On Tuesday, July 01, 2003 16:41:08 -0700 Jim Angstadt <jimajima9@yahoo.com> wrote:

  my $ua = LWP::UserAgent->new( timeout => 20, )
	|| die "Cannot create new LWP UserAgent: $! \n";
  my $req = HTTP::Request->new('GET', $url )
	|| die "Cannot create LWP Request: $! \n";
  $ua->request($req, \&callback, $block )
	|| die "Cannot request data: $! \n";
First of all, these lines are better written using "or" instead of "||". A line like

$var = foo() || die "...";

is interpreted as

$var = (foo() || die "...");

due to operator precedence. I don't think it matters here, but it's a bad habit to get into.

  sub callback
    {
	my ($html, $response, $protocol ) = @_;
	$html =~ s/^<html>.*Synopsis//;
	print LOG "\n\t html: \n $html \n";
	my @tr = $html =~ /<tr>.*?<\/tr>/gis;
	print LOG "\t Table rows: \n", join("\n", @tr),
"\n";
    }

The code gets delivered in chunks, so the print
statements are repeated.  Setting $block to 50k
(bigger than the page) did not help.
I've never really worked with LWP, but according to the manual you can just do:

my $response = $ua->request($req) or die ...;
print $response->content;

$response is a HTTP::Response object, with a method called "content" that returns the content of the response.

Alternately using the callback method, something like this would collect the content in a local variable:

my $html = '';
sub callback { $html .= $_[0] }
$ua->request($req, \&callback, $block ) or die...;
print $html; # Contains the response content


--
Kenneth Herron Kherron@newsguy.com 916-366-7338
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.