in reply to Re^3: 400 error
in thread 400 error
Hi, as hippo pointed out, this is not an SSCCE, and you are declaring $response twice. Additionally:
This is an SSCCE that should be copied into a file (eg 'foo.pl') and run with $ perl foo.pl http://example.com
... or this ...use strict; use warnings; use HTTP::Tiny; my $url = shift; my $response = HTTP::Tiny->new->get($url); if ( $response->{success} ) { print "OK: $response->{content}\n"; } else { print "Failed: $response->{status} $response->{reason}\n"; } __END__
use strict; use warnings; use LWP::UserAgent; my $ua = new LWP::UserAgent; # possibly add advanced user agent options here my $url = shift; # possibly construct a request object here my $response = $ua->get($url); # if not using a request object if ($response->is_success) { print $response->decoded_content, "\n"; } else { die $response->status_line; } __END__
Hope this helps! There are no shortcuts to learning, not if you want to understand.
|
|---|