我正在寻找一种方法来捕获PHP在Flex中使用HTTPService
抛出的异常。是否可以做到这一点不使用AMFPHP?
在我目前的实现中,如果在PHP中抛出一个异常,那么在Flex端确实会调度一个FaultEvent.FAULT
。唯一的问题是异常的消息字符串在FaultEvent
中无处可寻。
让我试着用一个例子来更好地解释。假设我们在服务器端有以下PHP代码:
<?php
throw new Exception("Exception message");
?>
在flex端,假设有一个HTTPService
实例调用上面的PHP代码。此外,它在FaultEvent.FAULT
上调用以下函数:
private function onFaultyResult(evt:FaultEvent):void {
//How do I get the exception message here?
}
如何在这个函数中从PHP获得异常消息?
注:trace(evt.toString())
给出:
[FaultEvent fault=[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: 192.168.1.119/exception.php"]. URL: 192.168.1.119/exception.php"] messageId="7FF021A3-8C83-CB14-081D-8C8438802204" type="fault" bubbles=false cancelable=true eventPhase=2]
我也在调试器的evt
的其他字段中寻找"异常消息",但找不到它。
谢谢
根本问题是Flash无法处理服务器返回的状态<> 200 http://www.robsondesign.com/blog/index.php/2009/04/16/flex-flash-and-http-status-codes/