Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Curl with perl

by palette (Scribe)
on Jan 22, 2009 at 06:53 UTC ( #738070=perlquestion: print w/replies, xml ) Need Help??
palette has asked for the wisdom of the Perl Monks concerning the following question:

I have a very simple script to post XML using curl to an URL
$xml ='<?xml version="1.0" encoding="UTF-8"?> <TEST xmlns:xsi=""> <TEST1> <ID>1223</ID> <DESCRIPTION>XXXXX</DESCRIPTION> </TEST1> </TEST> '; $curl ='/usr/local/bin/curl --silent -m 120 -d "'.$xml.'" '. 'http://l +ocalhost/check.cgi'; $responsexml = `$curl`; print $responsexml;
On executing the script I am getting this error.
org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
Pls let me know what is the reason for this error, and what needs to be verified to make it work.

Replies are listed 'Best First'.
Re: Curl with perl
by fullermd (Priest) on Jan 22, 2009 at 07:32 UTC

    Well, for one thing, note that you're including on the command-line a double-quoted string (the $xml), containing double-quotes. That doesn't tend to work well. Perhaps you should try using open to pass in the args as an array and grab the output?

    @curl = ('/usr/local/bin/curl', '--silent', '-m', '120', '-d', $xml, 'http://localhost/check.cgi'); open CURL, "-|", @curl; @responsexml = <CURL>; print @responsexml;


    As for the error you gave, there's nothing in the code you posted that would get near SAX (whether there's any surrounding code that may, you haven't said enough to guess). And I don't think curl uses it either. So presumably, that's coming from the server and has nothing (directly) to do with this code anyway.

Re: Curl with perl
by dHarry (Abbot) on Jan 22, 2009 at 08:49 UTC

    org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.

    This is a known problem, past the error message into Google and find the solution. Hint: "well-formedness".

Re: Curl with perl
by clscott (Friar) on Jan 23, 2009 at 00:47 UTC
    Are you aware of LWP? It could make your life easier
    $xml ='<?xml version="1.0" encoding="UTF-8"?> <TEST xmlns:xsi=""> <TEST1> <ID>1223</ID> <DESCRIPTION>XXXXX</DESCRIPTION> </TEST1> </TEST> '; use LWP::UserAgent; my $curl = LWP::UserAgent->new( timeout => 120 ); my $response = $curl->post($url, Content => $xml); if ($response->is_success) { print $response->decoded_content; # or whatever } else { die $response->status_line; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://738070]
Approved by davido
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2017-06-27 02:56 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (598 votes). Check out past polls.