Solved

LWP and auto-relocation: Turning Off?

Posted on 2000-05-10
8
200 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Existing perl code to be changed for ftp to sftp handling 14 212
compress files in RAR using perl 13 83
Perl 101 11 81
Edit Odbc.ini using perl module 2 90
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

809 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