Re: LWP::Simple::get returns undef for some Web pages

From: Joe Smith (joe_at_inwap.com)
Date: 12/27/04


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



Relevant Pages

  • RE: Uploading a Picture
    ... List Disk Drives ... The following sample code uses a StreamReader class to read the System.ini ... Dim ... End Sub ...
    (microsoft.public.vb.database)
  • Re: Dynamically add link button
    ... You may want to check out some sample code I've placed on my website. ... "simon" wrote in message ... > false.When user click the button set visibility to true and when choose ... >>> Private Sub Page_Load(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: PowerPoint VBA
    ... Here is some sample code. ... ' Remember you need to set a reference to Outlook in the VBE window. ... Sub MailThruOutlook() ... Bill Foley, Microsoft MVP ...
    (microsoft.public.powerpoint)
  • Statusbar
    ... In the below sample code, how do i determine/translate the "# of items to ... Sub TestBar() ... StatBar i, MyTot, "Processing", True ' display statusbar ... ' previous line speeds up the macro by not updating the statusbar for ...
    (microsoft.public.excel.programming)
  • Re: Application Events in Powerpoint
    ... Here's some sample code. ... commented the unload instruction; this seemed to fix the situation. ... Public Sub DoOffload() ... 98").Visible = msoTrue ...
    (microsoft.public.powerpoint)