Re: LWP::Simple::get returns undef for some Web pages
From: Joe Smith (joe_at_inwap.com)
Date: 12/27/04
- Next message: http://tinyurl.com/5em8l: "soc.culture.maghreb,comp.lang.perl.modules,rec.photo.marketplace.large-format,europa.sport,alt.autos.gm.j-body"
- Previous message: Sherm Pendley: "Re: LWP::Simple::get returns undef for some Web pages"
- In reply to: dave_nul_at_hotmail.com: "LWP::Simple::get returns undef for some Web pages"
- Next in thread: dave_nul_at_hotmail.com: "Re: LWP::Simple::get returns undef for some Web pages"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 27 Dec 2004 08:42:05 GMT
dave_nul@hotmail.com wrote:
> I'm trying to write a sub that can get all sorts of Web pages, and find
> that LWP::Simple::get works well for most non-authenticated pages, but
> not for all. Below is some sample code to illustrate. Any ideas on
> why the first get() fails to return anything but undef?
>
> use LWP::Simple qw( get );
> print get( 'http://www.worldtimeserver.com/time.aspx?locationid=UTC') .
> "\n";
# Quote from `perldoc LWP::Simple`:
# You will not be able to examine the response code or response head-
# ers (like 'Content-Type') when you are accessing the web using this
# function. If you need that information you should use the full OO
# interface (see LWP::UserAgent).
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)
Gecko/20041107 Firefox/1.0');
$ua->timeout(10);
my $url = 'http://www.worldtimeserver.com/time.aspx?locationid=UTC';
my $response = $ua->get($url, Host => 'www.worldtimeserver.com');
if ($response->is_success) {
print $response->content; # or whatever
}
else {
die $response->status_line;
}
When I run that, it says "500 Server Error".
This means that time.aspx is very fragile; it appears to die when
the HTTP headers do not exactly match IE or FireFox.
-Joe
- Next message: http://tinyurl.com/5em8l: "soc.culture.maghreb,comp.lang.perl.modules,rec.photo.marketplace.large-format,europa.sport,alt.autos.gm.j-body"
- Previous message: Sherm Pendley: "Re: LWP::Simple::get returns undef for some Web pages"
- In reply to: dave_nul_at_hotmail.com: "LWP::Simple::get returns undef for some Web pages"
- Next in thread: dave_nul_at_hotmail.com: "Re: LWP::Simple::get returns undef for some Web pages"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|