是否有可能做的Flex轻量级REST调用? [英] Is it possible to do lightweight REST calls in Flex?

查看:167
本文介绍了是否有可能做的Flex轻量级REST调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

在加入 mx.rpc.http.HTTPService 类到code,该SWF二进制产量增长从175KB到260KB。这是一个不能接受的打击。

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.

有没有更好的方式来做到轻量级REST从Flex应用程序调用?难道我们最好使用一个外部接口JS刚打的电话的呢?

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?

推荐答案

flash.net.URLLoader 内置在运行时,不会造成任何的文件大小增加。我用它作为一个JSON客户端之前,所以你不应该有任何麻烦吧。

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.

下面是一个非常简单的例子。请参阅<一个文件href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html#event%3ahttpStatus"相对=nofollow> HTTP_STATUS 和<一href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html#event%3ahtt$p$psponseStatus"相对=nofollow> HTTP_RESPONSE_STATUS 了解他们的限制的信息。

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

这篇关于是否有可能做的Flex轻量级REST调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆