Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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:

Hi,
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="http://www.w3.org/2001/XMLSchema-instance"> <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.

Comment on Curl with perl
Select or Download Code
Re: Curl with perl
by fullermd (Curate) 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;

    (untested)

    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="http://www.w3.org/2001/XMLSchema-instance"> <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; }
    --
    Clayton

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://738070]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2014-07-24 11:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (160 votes), past polls