Rajesh Dorairajan wrote:
>
> I've had this problem for a long time and I am in a sort of a dead-end and
> could use some help. When I make a get request using the LWP UserAgent
> inside a function and I pass a URL to the function as a string I get a
> response. However, when I pass a variable that contains the URL (typically a
> hash value) I get a return code of 501. I'm just not able to figure out why.
> I'm giving the example code of the working code and Non-working code. Any
> help will be deeply appreciated.
>
> Thanks in advance.
>
> -----------------------
> #Working code
>
> #!/usr/bin/perl
> use strict;
> use LWP::UserAgent;
> my $url = "http://rajeshd";;
>
> print_page ( $url );
>
> 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";
> }
> -----------------------
> #Failing code
>
> #!/usr/bin/perl
> use strict;
> use LWP::UserAgent;
> use XML::Simple;
>
> my $config = XMLin( "C:/config.xml", VarAttr => 'name',
>                     ContentKey => '-content' );
>
> my $url = $config->={URL_1}; #$config->{URL_1} equals http://rajeshd at run-time
>
> print_page ( $url );

Hi Rajesh.

$config->{URL_1} cannot be what you think it is. Put a print statement in
'print_page' to show both $host and length($host) to see how it differs.

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to