On 03/29/2007 06:39 AM, Beginner wrote:
Hi,
I might be in above my head here so bear with me if I am not making
sense.
I have to retrieve and extract an xml fragment from a REST server. I
have followed some examples from the "Web Services" book. I am able
to retrieve the data via LWP::UserAgent but I am baffled by the hash
ref that's returned. Data::Dumper prints it as this (excuse the
formatting) :
$VAR1 = bless( {
'_protocol' => 'HTTP/1.1',
'_content' => '<address id="1029">
<addressLine1>YORK</addressLine1>
<addressLine2>W1T 6RF</addressLine2>
<addressLine3></addressLine3>
<addressLine4></addressLine4>
<addressLine5></addressLine5>
<country id="227"/>
<postcode>W1T 6RF</postcode>
</address>',
'_rc' => 200,
'_headers' => bless( {
'client-date' => 'Thu, 29 Mar
2007 11:20:51 GMT',
'content-type' => 'text/xml',
'client-response-num' => 1,
'client-peer' =>
'127.0.0.1:8182',
'content-length' => '256',
'server' => 'Restlet-
Engine/1.0b14'
}, 'HTTP::Headers' ),
'_msg' => 'The request has succeeded',
'_request' => bless( {
'_content' => '',
'_uri' => bless( do{\(my $o =
'http://localhost:8182/core/address/1029')}, 'URI::http' ),
'_headers' => bless( {
'user-
agent' => 'libwww-perl/5.803'
},
'HTTP::Headers' ),
'_method' => 'GET'
}, 'HTTP::Request' )
}, 'HTTP::Response' );
I am not sure who I am work with the data. The bless reference means
I have just stepped into the murky workd of OO perl. The data I am
after is the address xml fragment at the top.
Can anyone offer me any tips to get me started? How do I reference
the 'Object' at the top of the response? Is there a module that will
help 'deserialize' the response?
Thanx,
Dp.
If all you want is the content of the response object, just use the
response object. You will first have to use the "HTTP::Response" module
so the methods are defined:
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Response;
use HTTP::Headers;
use URI::http;
use HTTP::Request;
our $VAR1;
$VAR1 = bless( {
'_content' => '<address id="1029">
<addressLine1>YORK</addressLine1>
<addressLine2>W1T 6RF</addressLine2>
<addressLine3></addressLine3>
<addressLine4></addressLine4>
<addressLine5></addressLine5>
<country id="227"/>
<postcode>W1T 6RF</postcode>
</address>',
'_protocol' => 'HTTP/1.1',
'_headers' => bless( {
'client-date' => 'Thu, 29 Mar 2007 11:20:51 GMT',
'content-type' => 'text/xml',
'client-response-num' => 1,
'server' => 'Restlet-Engine/1.0b14',
'content-length' => '256',
'client-peer' => '127.0.0.1:8182'
}, 'HTTP::Headers' ),
'_rc' => 200,
'_msg' => 'The request has succeeded',
'_request' => bless( {
'_content' => '',
'_uri' => bless( do{\(my $o =
'http://localhost:8182/core/address/1029')}, 'URI::http' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/5.803'
}, 'HTTP::Headers' ),
'_method' => 'GET'
}, 'HTTP::Request' )
}, 'HTTP::Response' );
#######################################
print "The content of the HTTP::Response object is this:\n";
print $VAR1->content, "\n";
__END__
Read the documentation for HTTP::Response: "perldoc HTTP::Response"
HTH
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/