PHP Socket response
Posted: Thu Sep 03, 2009 11:22 am
Hey guys...
I've got a working bit of code that pushes XML code to a web server (cisco phone)
It returns a variable called $response.... BUT it doesn't contain the info i actually want back from the phone!
Basically when i send the XML to the phone i should get back this as the $response variable:
<?xml version="1.0" encoding="iso-8859-1"?>
<CiscoIPPhoneResponse>
<ResponseItem URL="Key:Speaker" Data="Success" Status="0" />
</CiscoIPPhoneResponse>
instead i get back this:
HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Date: Thu, 03 Sep 2009 16:13:57 GMT
Expires: Thu, 26 Oct 1995 00:00:00 GMT
Last-Modified: Thu, 03 Sep 2009 16:13:57 GMT
Pragma: no-cache
Content-Length: 156
Server: Allegro-Software-RomPager/4.34
The phone is sending back both packets BUT its putting the wrong one into the $response variable... the correct one is the 2nd bit that the phone sends so I dont know if its just putting the first thing it receives into the variable...
any ideas how i can get it to return the correct response?
Code here:
I've got a working bit of code that pushes XML code to a web server (cisco phone)
It returns a variable called $response.... BUT it doesn't contain the info i actually want back from the phone!
Basically when i send the XML to the phone i should get back this as the $response variable:
<?xml version="1.0" encoding="iso-8859-1"?>
<CiscoIPPhoneResponse>
<ResponseItem URL="Key:Speaker" Data="Success" Status="0" />
</CiscoIPPhoneResponse>
instead i get back this:
HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Date: Thu, 03 Sep 2009 16:13:57 GMT
Expires: Thu, 26 Oct 1995 00:00:00 GMT
Last-Modified: Thu, 03 Sep 2009 16:13:57 GMT
Pragma: no-cache
Content-Length: 156
Server: Allegro-Software-RomPager/4.34
The phone is sending back both packets BUT its putting the wrong one into the $response variable... the correct one is the 2nd bit that the phone sends so I dont know if its just putting the first thing it receives into the variable...
any ideas how i can get it to return the correct response?
Code here:
Code: Select all
$xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Key:".$key."'/></CiscoIPPhoneExecute>";
$posttxt = "/CGI/Execute";
sendXML($xml,$posttxt)
function sendXML($xml,$posttxt)
{
$ip = $_POST['IP'];
$userid = $_POST['USERID'];
$pin = $_POST['PIN'];
$auth = base64_encode($userid.":".$pin);
$xml = "XML=".urlencode($xml);
$post ="POST $posttxt HTTP/1.0\r\n";
$post.="Host: $ip\r\n";
$post.="Authorization: Basic $auth\r\n";
$post.="Connection: close\r\n";
$post.="Content-Type: application/x-www-form-urlencoded\r\n";
$post.="Content-Length: ".strlen($xml)."\r\n\r\n";
$response = "";
$sock = fsockopen($ip, 80, $errno, $errstr, 30);
if ($sock) {
fwrite($sock, $post . $xml);
while (!feof($sock)) {
$response .= fgets($sock, 128);
}
fclose($sock);
}
echo $response;