This section provides a tutorial example on how to use the content_type() method in the HTTP::Headers class to set the Content-Type header line with 'application/soap+xml'.
The second option of getting "Content-Type: application/soap+xml"
is to set content_type in object $http_request explicitly.
To do this we need to find a way to reach $http_request inside $client.
Since Perl objects are all hash tables, the Data::Dumper can help us to
see the inner structure of the $client hash table:
#- GetSpeech_Data_Dumper.pl
#- Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
#- All rights reserved
#
use Data::Dumper;
use SOAP::Lite;
my $client = SOAP::Lite->new()
->soapversion('1.2')
->envprefix('soap12')
->default_ns('http://xmlme.com/WebServices')
->on_action( sub {join '/', @_} )
->readable(true)
->proxy('http://localhost/WSShakespeare.asmx');
print Dumper($client);
I read the HTTP::Request manual.
It inherits the method content_type() from the HTTP::Headers class.
So my solution will be calling content_type() to set Content-Type
after my $client object is ready.
#- GetSpeech_Content-Type_Method.pl
#- Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
#- All rights reserved
#
use SOAP::Lite +trace;
my $client = SOAP::Lite->new()
->soapversion('1.2')
->envprefix('soap12')
->default_ns('http://xmlme.com/WebServices')
->on_action( sub {join '/', @_} )
->readable(true)
->proxy('http://localhost/WSShakespeare.asmx');
#- Setting Content-Type myself
my $http_request = $client
->{'_transport'}
->{'_proxy'}
->{'_http_request'};
$http_request->content_type('application/soap+xml');
my $som = $client->call('GetSpeech',
SOAP::Data->name("Request")
->value("To be, or not to be")
);