Solved

LWP and auto-relocation: Turning Off?

Posted on 2000-05-10
8
201 Views
Last Modified: 2010-03-05
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?
0
Comment
Question by:ljaques
8 Comments
 
LVL 8

Accepted Solution

by:
shlomoy earned 5 total points
ID: 2798967
use LWP::Simple qw($ua);

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

$ua->timeout(10);
my ($request, $response);

$request = HTTP::Request->new(GET => $url_str);
$response = $ua->request($request, $file);


-------
$response holds an HTTP::Response object which you can query for the exact return code, and act accordingly.

The timeout might not work for you because you didn't request for $ua when you use LWP::Simple.
0
 

Author Comment

by:ljaques
ID: 2799295
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
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2800467
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.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ljaques
ID: 2802048
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.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2802147
what about the redirection??

is that still happening too??

0
 
LVL 12

Expert Comment

by:geotiger
ID: 2807431
listening ...
0
 

Author Comment

by:ljaques
ID: 2807493
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.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2810816
"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.

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question