PERL LWP routine cannot contact internet

They have: 2 posts

Joined: Nov 2004

I have a PERL routine that saves a backup copy of a url using the LWP::Simple module. It works reliably on Windows servers. I have just set up a machine with the J2EE environment and Tomcat web server, and the routine will not run through the server on this machine (although it will run from the command prompt). I presume this means that the problem is somewhere in the server setup or permissions, but I can’t seem to locate anything that resolves the problem. I need to get this working through the browser because it is part of a web-based system. Any suggestions on what needs tweaked?

Here is an abbreviated copy of the code:

sub CheckSave{

my $id = $_[0]; #passing primary key

my $url = $_[1]; #whether or not to save backup

my $savepath = $_[2];

#check web page header to see if it exists

@dat=head($url);

if (!@dat) {

print <

System cannot contact the Internet to save a backup. Please contact the webmaster

or edit the web address entered.

URL: $url

EOF

;

die;

}

#get extension for saved file from url

$ext=$in{"cec_url"};

if ($ext =~ /\?/ || $ext =~ /.com$/) {

#if url contains a query string, use header to return extension

#if .com address, use content_type

$ext=$dat[0];

$ext =~ s/.*\/(.*)/\1/;

} else {

#otherwise, find the file type from the url

$ext =~ s/.*\.([^\/]*)/\1/;

}

#save the new web download

$saveFile = $savepath.$id.".".$ext; #generate archive file name

$status = getstore($in{"cec_url"}, $saveFile); #check url and save copy

if (is_success($status)) {

print qq[Backup copy saved.\n];

} else {

#print warning if website was not valid

print <

Website link not found. Archive file not saved.

Please edit this record.

EOF

;

}

}

They have: 2 posts

Joined: Nov 2004

For anyone else who has this problem, adding the line

$ENV{"SYSTEMROOT"} = "C:\\windows";

fixed it.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.