问题描述
我使用 URLLoader 将数据加载到我的 Flex 应用程序(主要是 XML)中,而我做同样事情的伙伴主要使用 HTTPService.是否有特定或有效的理由来使用另一个?
I use URLLoader to load data into my Flex app (mostly XML) and my buddy who is doing the same thing mostly uses HTTPService. Is there a specific or valid reason to use on over the other?
推荐答案
HTTPService 继承了 AbstractInvoker,它允许您使用 URLLoader 无法使用的令牌和响应程序.当您需要传递与请求相关的特定变量(您希望与响应一起返回)时,令牌非常有用.
HTTPService inherits AbstractInvoker which allows you to use tokens and responders which you cannot use with URLLoader. Tokens are good when you need to pass specific variables that are relevant to the request, which you want returned with the response.
除此之外,使用 URLLoader 或 HttpService 加载 xml 都是一样的.
Other than that, using URLLoader or HttpService to load xml is the same.
示例:
var token:AsyncToken = httpService.send({someVariable: 123});
token.requestStartTime = getTimer();
token.addResponder(new AsyncResponder(
function (evt:ResultEvent, token:Object):void {
var xml:XML = evt.result as XML;
var startTime = token.requestStartTime;
var runTime = getTimer() - startTime;
Alert.show("Request took " + runTime + " ms");
//handle response here
},
function (info:Object, token:Object):void {
//handle fault here
},
token
));
这篇关于Flex - URLLoader 和 HTTPService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!