是否可以在 Flex 中进行轻量级 REST 调用?

发布于 2024-10-08 04:35:15 字数 199 浏览 0 评论 0原文

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

mx.rpc.http.HTTPService 类添加到代码中后,SWF 二进制输出从 175KB 增加到 260KB。这是一个不可接受的打击。

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

We are converting a Flex application to use some REST APIs.

When adding the mx.rpc.http.HTTPService class to the code, the SWF binary output grew from 175KB to 260KB. This is an unacceptable hit.

Is there any better way to do lightweight REST calls from a Flex app? Are we better off using an external interface JS just to make the calls from there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落花随流水 2024-10-15 04:35:15

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);

flash.net.URLLoader is built into the runtime and won't cause any increase in filesize. I've used it as a JSON client before, so you shouldn't have any troubles with it.

Below is a very simple example. See documentation for HTTP_STATUS and HTTP_RESPONSE_STATUS for information on their restrictions.

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);
灯下孤影 2024-10-15 04:35:15

我一直认为一个好的方法是为浏览器的 JavaScript HTTP API XmlHttpRequest 创建一个小接口。我从未尝试过,但我研究过,看起来可能相当简单。

这将带来额外的好处,那就是绕过 Flash Player 的安全限制,这些限制使其 HTTP 支持严重受损。

I've always thought a good approach to this would be to create a small interface to the browser's JavaScript HTTP API, XmlHttpRequest. I've never tried it, but I've looked into it, and it looked like it might be fairly straightforward.

This would have the added benefit of working around Flash Player's security restrictions which make its HTTP support terribly crippled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文