[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 824
  • Last Modified:

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
1 Solution
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.
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

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?

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now