ZendAMF returning invalid XML and causing BadVersion error when called method from Flash
I am trying to use ZendA开发者_如何学运维MF to do remote method calls to a MySQL database from Flash and I keep recieving the NetConnection.Call.BadVersion error.
My Server is working correctly. Apache 2.2.14
My PHP is working correctly. PHP 5.2.11
My Database is working. MySQL 5.0
UPDATE: My first problem was a security error in Flash. If you try to run a local SWF from the Flash IDE to a web service online, you'll get a security warning which will throw the BadVersion error. However, the security error won't show up if you 'TEST MOVIE' so it took me a while to realize that. I changed my testing process to remove this variable. I am now able to implement my php class code successfully using AMFPHP, which essentially rules out my class as the issue (I think). It seems to be a problem with the Zend implemntation of AMF.
I have followed a tutorial from Lee Brimlow here: http://www.gotoandlearn.com/play.php?id=90 . I was unable to get this to work locally, and I've moved my content onto a web server and can call the Class and Method from my SWF. I've used Charles to view the response. When I go to validate the response in Charles I get this:
Validator: Failed to Parse XML Document.
Reason: An invalid XML character (Unicode: 0x0) was found in the CDATA section.
Line: 65 Column: 87
Any ideas how to fix this? Can it be handled in PHP?
Here is my ZendAMF code:
<?php
error_reporting(E_ALL|E_STRICT);
ini_set("display_errors", "on");
ini_set("include_path", "./frameworks");
require_once 'Zend/Amf/Server.php';
require_once 'Animal.php';
$server = new Zend_Amf_Server();
$server->setClass("Animal");
$server->setProduction(false);
$response = $server->handle();
echo $response;
?>
Here is my PHP Class code: (note no closing ?> tag.)
<?php
class Animal
{
public function __construct()
{
include "dbinfo.inc.php";
$linkID = mysql_connect('localhost', $username, $password) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die( "Unable to select database.");
}
public function getAnimalQuotes()
{
$result = mysql_query("SELECT * FROM AnimalQuotes");
$t = array();
while($row = mysql_fetch_assoc($result))
{
array_push($t, $row);
}
return $t;
}
}
I've updated my Flash Player to 10.1. I'm publishing my swf to Flash 10/AS3.
I'm still getting this error when I run my SWF.
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
at ZendAMF_fla::MainTimeline/frame1()
Here is my AS3 code:
import flash.net.*;
var nc:NetConnection = new NetConnection();
nc.connect("http://www.pbjs.com/2010/");
var res:Responder = new Responder(onResult, onFault);
nc.call("Animal.getAnimalQuotes", res);
function onResult(e:Object):void
{
trace (e);
}
function onFault(e:Object):void
{
for (var i in e){
trace(e[i]);
}
}
does the connection work in the standalone player? check the logs of your client and see the errors that are thrown. the IDE connects in a different manner to the standalone and it might be throwing a security error.
Have you checked your PHP code? The NetConnection.Call.BadVersion error is a typical error if your PHP code has an error. Before debugging the Flash side, be 100% sure that your PHP code is working and returning the results you expect.
You ready for this?! The Zend Framework gateway file cannot have any space before the opening PHP tag or the AMF response will be invalid.
My only issue was that I had nothing on line 1 and my opening PHP tag on line 2.
That was the issue. Working Code below!
<?php // MAKE SURE THIS IS LINE 1
// Configurable values
// Debugging values
$debug = true; // Debugging status
if ($debug)
{
// Report all errors, warnings, interoperability and compatibility
error_reporting( E_ALL | E_STRICT );
// Show errors with output
ini_set( "display_errors" , "on");
}
else
{
error_reporting(0);
ini_set("display_errors", "off");
}
// Add the Zend AMF installation folder to PHP include path
ini_set( "include_path", "./frameworks/library");
// Instantiate the Zend Amf server
require_once( "Zend/Amf/Server.php" );
require_once("Animal.php");
$server = new Zend_Amf_Server();
$server->setClass("Animal");
// Return the handle.
$response = $server->handle();
echo $response;
?>
精彩评论