jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:
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; } } ?>
But, by way of exceeding enlightenment I receive this from the server: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; }
Which leads me to believe that maybe I have an escaping or encoding issue? Can anybody help me please?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." />
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A newbie XML and HTTP question.
by bmann (Priest) on Jul 12, 2005 at 20:04 UTC | |
by jdtoronto (Prior) on Jul 12, 2005 at 20:05 UTC | |
by samtregar (Abbot) on Jul 12, 2005 at 21:44 UTC |