0

What are the elements of the class response from this code: Or, how can I print the entire object response ?

#!/usr/bin/env perl


# Example code from Chapter 1 of /Perl and LWP/ by Sean M. Burke

# http://www.oreilly.com/catalog/perllwp/

# [email protected]


require 5;

use strict;

use warnings;


use LWP;


my $browser = LWP::UserAgent->new();

my $response = $browser->get("http://www.oreilly.com/");

die "Couldn't access it: ", $response->status_line

 unless $response->is_success;

print $response->header("Server"), "\n";

__END__

1 Answer 1

1

Like this, if you want to get the HTML content:

use strict; use warnings;

my $arg1 = "Rower";

# Create a user agent object
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;

# Create a request
my $req = HTTP::Request->new(GET => "http://pl.wikipedia.org/wiki/$arg1");

# Pass request to the user agent and get a response back
my $res = $ua->request($req);

# Check the outcome of the response
die $res->status_line, "\n" unless $res->is_success;

# Here we go
my $content = $res->content;
print $content;

Or if you want to literally get $res content object for inspection:

use Data::Dumper;
print Dumper $res;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .