是否有可能做的Flex轻量级REST调用?有可能、Flex、REST

由网友(超长的经典大全精选)分享简介:我们正在转换Flex应用程序使用一些的REST API。We are converting a Flex application to use some REST APIs.在加入 mx.rpc.http.HTTPService 类到code,该SWF二进制产量增长从175KB到260KB。这是一个不能接受的打击。...

我们正在转换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.

下面是一个非常简单的例子。请参阅 HTTP_STATUS 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);
阅读全文

相关推荐

最新文章