David,
I tried this out. Still no luck. Then I tried a small vairation of your
code:
my ( $Host, $Port ) = @_;
my $url = $Host;
$url .= ":$vesPort" if ( $vesPort && $vesPort != 80 );
This works!!!! Apparently LWP does not like it when the default port is
specified in the GET requests in some circumstances. But it works fine if I
hard-code the $url = "http://servername:80". I am not sure if this is a bug
in the latest version of LWP. I've version 5.72
Thanks anyway. Also, thanks drieux to your suggestions too.
Rajesh
-----Original Message-----
From: david [mailto:[EMAIL PROTECTED]
Sent: Monday, November 10, 2003 3:19 PM
To: [EMAIL PROTECTED]
Subject: Re: Peculiar problem using LWP::UserAgent
Rajesh Dorairajan wrote:
> I ran into peculiar problem using LWP::UserAgent. I receive a 501 - Not
> yet implemented error when I connect to a web-server using the User-Agent.
> This happens when I pass in the Hostname and Portnumber as parameters in
> my function. However, if I hard-code the Server-name and port number it
> seems to work fine. I've included the piece of causing the problem below.
> Does anyone have suggestion why this is happening?
>
>
> my ( $Host, $Port ) = @_;
> my $url = "$Host:$Port"; #Does not work
> #my $url = "http://servername:80" #This works
>
> require LWP::UserAgent;
> my $ua = LWP::UserAgent->new(env_proxy => 0,
> keep_alive => 0,
> timeout => 30,
> );
>
> $response = $ua->get( $url );
>
are you sure you construct the right path? for example:
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
sub print_page{
my($host,$port) = @_;
my $url = $host;
$url .= ":$port" if($port);
my $ua = LWP::UserAgent->new(env_proxy => 0,
keep_alive => 0,
timeout => 30);
my $r = $ua->request(HTTP::Request->new(GET => $url));
print $r->content if($r->is_success);
print $r->code,': ',$r->status_line unless($r->is_success);
print "\n";
}
print_page('http://google.com'); #-- works fine
print_page('http://google.com',80); #-- works fine
print_page('google.com'); #-- 400: URL must be absolute
print_page('google.com',80); #-- 501: Protocol not supported
__END__
you are most likely seeing the last one. make sure you specify the protocol.
david
--
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$
";
map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*
#,
goto=>print+eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]