inblosam has asked for the wisdom of the Perl Monks concerning the following question:
Here is the perl code now. I can't figure out where the "ivrapi.asp" has to go, nor where to slide in the XML code through the socket to the server. When I run the code below it just sits, nothing back, but keeps running.<?php $XML = '<somexml></somexml>'; // 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; } ?>
I have looked at IO::Socket::INET but it seems to have just the same components as the Socket module in the code above. The perlipc page gave me the example code using Socket. And if its helpful, the server is not my server so I only have the client to work with.#!/usr/bin/perl -w use strict; use Socket; my ($remote,$port, $iaddr, $paddr, $proto, $line); $remote = 'api.voiceshot.com'; $port = 80; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; while (defined($line = <SOCK>)) { print $line; } close (SOCK) || die "close: $!"; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Socket (to mimic PHP code)
by gellyfish (Monsignor) on Jun 07, 2006 at 15:19 UTC | |
by inblosam (Monk) on Jun 07, 2006 at 16:02 UTC | |
|
Re: Perl Socket (to mimic PHP code)
by Joost (Canon) on Jun 07, 2006 at 15:21 UTC |