Flex: HttpService正常返回Html, 但派发FaultEvent事件的解决方法

Categories: Flex; Tagged with: ; @ January 15th, 2010 21:51

HttpService的默认resultFormat为”object” HTTPService.RESULT_FORMAT_OBJECT 在服务器响应后, AbstractOperatoin.processResult()会对响应进行初步处理,

if (resultFormat == RESULT_FORMAT_XML || resultFormat == RESULT_FORMAT_OBJECT 
                    || resultFormat == RESULT_FORMAT_ARRAY)
            {
                //old XML style
                var tmp:Object = new XMLDocument();
                XMLDocument(tmp).ignoreWhite = true;
                try
                {
                    XMLDocument(tmp).parseXML(String(body));
                }
                catch(parseError:Error)
                {
                    var fault:Fault = new Fault(ERROR_DECODING, parseError.message);
                    dispatchRpcEvent(FaultEvent.createEvent(fault, token, message));
                    return false;
                }
		....
}



因此, 如果HttpService不set resultFormat的话, 会默认作为xml进行解析, 此时如出现错误, 则会派发FaultEvent.
为避免此问题, 可设定:
httpService.resultFormat = HTTPService.RESULT_FORMAT_TEXT;

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.