Link to home
Start Free TrialLog in
Avatar of ljaques
ljaques

asked on

LWP and auto-relocation: Turning Off?

I am using Perl 5.6 on Windows 98. I am using LWP to make http requests to websites.  I notice it auto relocates to new locations when a website sends back its 320 Reloc response.  I want to get back the full response and have LWP "not" auto relocate.

One little extra question: how do I get TIMEOUT to work?  I am connecting to a proxy or trying to retrieve a GIF and the server is not accepting the request or is taking too long to fill the request.  How do I set the timeout for accepting a request AND for a server to fill the request in its entirety?  $UA->TIMEOUT(10)  just doesn't seem to work when I connect to no-existant proxies or websites.  It just seems to timeout at its default 3 mins or somethine.

Thanks

How do I do this?
ASKER CERTIFIED SOLUTION
Avatar of shlomoy
shlomoy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ljaques
ljaques

ASKER

Hi shlomoy.

This is the code I'm using:

---
use LWP::Simple qw($ua);

$url_str = "http://www.av/com/";
$file = "/tmp/myfile";

$ua->timeout(20);
my ($request, $response);
$ua->proxy(http,"http://922.2.122.106:80");

$request = HTTP::Request->new(GET => $url_str);
print "Requesting...\n";
$response = $ua->request($request);
print $response->as_string;
---

LWP will try to connect to the proxy first and find that it doesn't exist.  It returns back "500 Internal error (Timeout)"  which is great but it takes at least 1 minute to timeout.  It seems to ignore $ua->timeout(20).  I would love to have it timeout in 20 secs.  Is $ua->timeout only good for timingout  on data that is presently sending back but is taking too long to complete?  I would love to have control over this as well as conncection timeout.

Thanks for any extra help
in your code you are using us, but it seems you have not created an UserAgent object!!

add the foll line....
$ua= new LWP::UserAgent;


BEFORE ....

$ua->timeout(20);


Also add the foll line...

print "Content-type: text/html\n\n";

BEFORE ....

print "Requesting...\n";

Let me know how it goes.

Avatar of ljaques

ASKER

Hi again guys.

I placed in the $ua=new LWP::UserAgent into the code above as suggested but it still doesn't timeout in 10 secs or 20 secs.  It times out in its own hard wired 1 minute or so.

Maybe it has something to do with it running in MSDOS (I have Windows 98 using Perl 5.6 from Active State).

Thanks for any more help.
what about the redirection??

is that still happening too??

listening ...
Avatar of ljaques

ASKER

yes for redirection still happening.  :(
Though I am more interested in the timeout problem.  At least I would love to have LWP timeout any dead remote connections (ie. proxies or remote site) by 30 secs.  

Thanks.
"I... have Windows 98 using Perl 5.6 from Active State). ...."

Hmm!! can you try the same program using older version of PERL??

just a few Q's back another user had a problem using sockets on PERL 5.6. it was solved when the user went back to the older version.