Send XML to a Perl script

I am trying to write a RESTful web service in Perl.

I have a perl script that can read in XML using XML::Simple which is sitting at a particular URL. I want to send XML to that script from another thing (be it a web page, application etc.).

What I don't know is how I'd go about getting the Perl to realise XML was being sent to it and load that XML into XML::Simple (or any other XML module if another is more relevant).

Thanks for any help
Who is Participating?
Adam314Connect With a Mentor Commented:
If the script is being called as a URL, it is likely getting it's data the same way a GET or POST request would.  If so, you can use the CGI module to handle getting the data.  Something like this:
########## To display all parameters
use strict;
use CGI ':standard';
print header('text/plain');
foreach (param()) {
    print "$_ = " . join(", ", param($_)) . "\n";
########## To get one, and use it with XML::Simple
use strict;
use CGI ':standard';
use XML::Simple;
my $XMLstring = param('XML');
my $xml = XMLin($XMLstring);
#Now, $xml is a reference to your xml data

Open in new window

are you trying to do this by modifying the code in the script, or by invoking the script in a particular way?
in either case it may help to see how the script is now realizing its input.
intechfsAuthor Commented:
The XML is sent from something, like say a PHP script which calls the Perl at a particular URL.

I don't want to have to attach it as a GET variable or POST if it can be avoided.

I haven't written the Perl that reads in the XML yet, but when I do I will probably be using XML::Simple to do so.
intechfsAuthor Commented:
Thanks for this, works great.
I wanna know how can i send an XML to a perl web service from a php page? So many of the articles in the web shows that a request must be a HTTP GET/POST only. If it so then how can i send an XML as a input to a perl web service?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.