[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] LWP woes



Hi:

I'm trying to get a series of files from a server.  I've included all 
the whole code below.

Basically, the first time I make the LWP and HTTP calls, everything 
works just peachy, and it prints out the file I'm trying to get.  Any 
and all subsequent calls however generate an error, which I'm 
assuming is coming from the server 500 - # Illegal content in request 
() but I realize isn't necessarily server generated.

You'll notice in the code that I repeat a set of statements twice, 
which are identical except in variable names.  First one works, 
second one doesn't.  Loop seems to run fine and pass variables fine 
etc.

Thanks very much for any help!

Code:

#! perl

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
#use strict;


my @theURL = ("http://www.live365.com/scripts/footer-ec.js",
 
	"http://www.live365.com/scripts/subnav-broadcast-ec.js",
				"http://www.live365.com/scripts/navbar-ec.js",
 
	"http://www.live365.com/scripts/iseverything.js",
				"http://www.live365.com/scripts/genredata.js",
				"http://www.live365.com/scripts/genre.js",
 
	"http://www.live365.com/scripts/cookiemonster.js",
				"http://www.live365.com/scripts/djpanel.js",
				"http://www.live365.com/scripts/bitrates.js",);

print $#theURL . "\n\n";
print ($#theURL +1) . "\n\n";



for ($i = 0;$i != ($#theURL + 1);$i++) {

  	print ":::the original: $i ::: " . $theURL[$i] . " :::\n";
#
# 	my $URLToPass = $theURL[$i];
#
# 	print ":::theURLToPass::: " . $URLToPass . " :::\n";

	getTheJavascript($theURL[$i]);

}


sub getTheJavascript {

	my $myPal = @_[0];

	print $myPal . "::: \n\n";

	my $ua = new LWP::UserAgent;

	my $request = new HTTP::Request("GET", $myPal);

	my $response = $ua->request($request);

	print "\n\n :::-" . $request->as_string() . "-:::\n\n";

	if ($response->is_success) {

		my $theContent = $response->content;
		while ($theContent =~ s/\012/\n/) {};
		print $theContent;

	} else {

		print $response->error_as_HTML;
	}

		my $myPal = @_[0];

	print $myPal . "::: \n\n";

	my $uaToo = new LWP::UserAgent;

	my $requestToo = new HTTP::Request("GET", $myPal);

	my $responseToo = $ua->request($requestToo);

	print "\n\n :::-" . $requestToo->as_string() . "-:::\n\n";

	if ($responseToo->is_success) {

		my $theContentToo = $responseToo->content;
		while ($theContentToo =~ s/\012/\n/) {};
		print $theContentToo;

	} else {

		print $responseToo->error_as_HTML;
	}

# 	open THESCRIPZ, ">>:scripz:thescripts.txt" or die ("Can't 
open scripts!");
#
# 	print THESCRIPZ $theContent;
#
# 	close THESCRIPZ;

}

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org