apache-flex - 是否可以在 Flex 中执行轻量级 REST 调用?

标签 apache-flex actionscript-3 rest remoting

我们正在转换 Flex 应用程序以使用一些 REST API。

mx.rpc.http.HTTPService 类添加到代码后,SWF 二进制输出从 175KB 增加到 260KB。这是 Not Acceptable 打击。

有没有更好的方法从 Flex 应用程序进行轻量级 REST 调用?我们是否最好使用外部接口(interface) JS 只是从那里进行调用?

最佳答案

flash.net.URLLoader内置于运行时中,不会导致文件大小增加。我之前将其用作 JSON 客户端,因此您应该不会有任何问题。

下面是一个非常简单的例子。请参阅 HTTP_STATUS 的文档和 HTTP_RESPONSE_STATUS有关其限制的信息。

var request: URLRequest = new URLRequest("http://tempuri.org/service/json");
request.method = "POST";
request.contentType = "application/json";
request.data = JSON.encode(jsonObject);

var loader : URLLoader = new URLLoader(request);

// Only supported by some browsers
loader.addEventHandler(HTTPStatusEvent.HTTP_STATUS, statusCodeReceived);

// AIR only
loader.addEventHandler(HTTPStatusEvent.HTTP_RESPONSE_STATUS, statusCodeReceived);

loader.addEventHandler(Event.COMPLETE, function(ev:Event):void
{
    var responseJson : String = request.data as String;

    var responseJsonObject : String = JSON.decode(responseJson);
});

loader.addEventHandler(SecurityErrorEvent.SECURITY_ERROR, errorHandler);
loader.addEventHandler(IOErrorEvent.IO_ERROR, errorHandler);

关于apache-flex - 是否可以在 Flex 中执行轻量级 REST 调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4483098/

相关文章:

php - Flex - 如何将 Flex DropDownList 的所选项目的 ID 发送到服务器?

apache-flex - Hello World 失败,错误为 "Error: Could not resolve <s:Application> to a component implementation"

actionscript-3 - AS3如何使用appendBytes限制AAC流音频的NetStream缓冲

java - Spring 将大量对象列表发送到 Controller

java - swagger oauth 明白了,那么现在怎么办?

web-services - SQL 触发器可以调用 Web 服务吗?

ios - OneSignal 上的关键警报支持不起作用

javascript - 为客户提供免费的 pdf 阅读器

actionscript-3 - FlashDevelop语法错误: Expecting Identifier Before Public

flash - ActionScript 3 : get display object at pixel