Reputation: 6350
I am using SOAP::Lite for a service .Now what i want is to save the request and response xml for that a soap request but i am not able to get the xml for request and response .
SOAP
$soap_object->on_action( sub { $soapAction->{Auth} });
my $response = $soap_object->Auth(
SOAP::Data->type('string')->name('strUserName')->value($user_name),
SOAP::Data->type('string')->name('strPassword')->value($password)
);
For this request i want to save the request and response .Please suggest where i can get the required XML
Upvotes: 1
Views: 1301
Reputation: 54373
A bit of googling reveals that SOAP::Lite's underlying user agent (which is called the transport layer) is LWP::UserAgent. You can add handlers to the user agent that do stuff with the request and response objects when they are sent or received.
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->add_handler( request_prepare => sub { my($req, $ua, $h) = @_; say $req->decoded_content; });
$ua->add_handler( response_done => sub { my($res, $ua, $h) = @_; say $res->decoded_content; });
$ua->get('http://www.example.org');
This code will output an empty GET request body, and some HTML response.
SOAP::Lite's documentation tells us how to get the transport client.
my $transport = $soap_object->transport; # or $client
Now that thing should be a subclass of LWP::UserAgnt, and you should just be able to set handlers on it. I don't have any SOAP things handy to try this, but I have done it in the past.
Alternatively you could also subclass SOAP::Transport::HTTP::Client and add your own stuff to it that dumps every request/response pair as nicely indented XML. You could then use that client as a drop-in replacement.
Upvotes: 2