Reputation:
I want to send some XML from a Perl program to a CGI script that makes use of XML::Simple to take that XML as input and send XML as output.
Is there a way to send XML to a CGI script from Perl? Any help in this regards would be really appreciated.
Thank You
Upvotes: 2
Views: 3358
Reputation: 4848
One of the possible solutions would be use the HTTP::Request::Common module, which exposes some useful functions like GET
, POST
and HEADER
.
Assuming you want to use POST
to send the data to the remote application, you could do:
use HTTP::Request::Common;
use LWP::UserAgent;
my $url = 'http://localhost/cgi-bin/mycgi.pl';
my $xml = "<root></root>";
my $request = POST $url, Content_Type => 'text/xml; charset=utf-8', Content => $xml;
my $ua = LWP::UserAgent->new();
my $response = $ua->request($request);
if ( $response->is_success() ) {
print $response->content();
}
else {
warn $response->status_line, $/;
}
Hope this helps!
Upvotes: 2
Reputation: 132914
There's nothing special about XML: it's just text. Send it like you would send any other text. Is there something else that isn't working for you? What have you tried already?
If you're having trouble sending anything to the CGI program, take a look at a framework such as WWW::Mechanize which does most of the work of the request and response loop for you.
Upvotes: 0