Solved

LWP and auto-relocation: Turning Off?

Posted on 2000-05-10
8
196 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:ljaques
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 16

Expert Comment

by:maneshr
Comment Utility
what about the redirection??

is that still happening too??

0
 
LVL 12

Expert Comment

by:geotiger
Comment Utility
listening ...
0
 

Author Comment

by:ljaques
Comment Utility
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
Comment Utility
"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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now