Esteemed monks,

I have the enviable task of replacing some PHP code with Perl code. The PHP code was written to submit some XML to a remote server. Here it is:

<?php $XML = "<campaign action=\"6\" />"; if ($_POST['submit'] == 'view') { header("Content-type: text/xml"); echo $XML; } else { // Post header $VS_header = "POST /ivrapi.asp HTTP/1.0\r\n"; $VS_header .= "User-Agent: IVR API\r\n"; $VS_header .= "Host: api.voiceshot.com\r\n"; $VS_header .= "Content-Type: text/xml\r\n"; $VS_header .= "Content-length: ".strlen($XML)."\r\n"; $VS_header .= "Connection: close\r\n\r\n"; $stream = fsockopen("api.voiceshot.com", 80); if($stream) { fputs($stream, $VS_header); fputs($stream, $XML); $response=""; $header = ""; // code for parsing out the returned header do $header.=fread($stream,1); while (!preg_match('/\r\n\r\n$/',$header)); // Everything left is the XML response from the API while(!feof($stream)) $response .= fgets($stream, 1024); fclose($stream); header("Content-type: text/xml"); echo $response; } } ?>
All of this XML stuff is very new to me, but I assumed I could do this as an equivalent:
sub _vs_connectivity_check { my $self = shift; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST => 'http://api.voiceshot.com/ivrap +i.asp'); $req->content_type("text/xml"); $req->content( '<campaign action="6">'); my $res = $ua->request($req); print $res->as_string; }
But, by way of exceeding enlightenment I receive this from the server:
HTTP/1.1 200 OK Cache-Control: private Connection: close Date: Tue, 12 Jul 2005 19:27:30 GMT Server: Microsoft-IIS/5.0 Content-Length: 87 Content-Type: text/html Client-Date: Tue, 12 Jul 2005 19:34:08 GMT Client-Peer: 64.105.135.234:80 Client-Response-Num: 1 Set-Cookie: ASPSESSIONIDACCABCRB=LPAGGBNCGIBHEMOHFDCAAMLJ; path=/ <?xml version="1.0"?><campaign errorid="3" comment="XML file malformed + or missing." />
Which leads me to believe that maybe I have an escaping or encoding issue? Can anybody help me please?

jdtoronto


In reply to A newbie XML and HTTP question. by jdtoronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.