如何在 Actionscript 3 中访问 REST 服务? [英] How to access REST service in Actionscript 3?
本文介绍了如何在 Actionscript 3 中访问 REST 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在'http://localhost:3000/api/user/id'写了一个api服务,做一个GET,可以得到一个JSON响应.
I have write a api service at 'http://localhost:3000/api/user/id', do a GET, can get a JSON response.
如何从 actionscript3 访问这个服务?
How to access this service from actionscript3?
推荐答案
您可以使用一个简单的 URLRequest
:
You can do this using a simple URLRequest
:
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
try
{
loader.load(new URLRequest("http://localhost:3000/api/user/id"));
}
catch (error:Error)
{
trace("Error loading URL: " + error.message);
}
function loaderCompleteHandler(e:Event):void
{
// and here's your response (in your case the JSON)
trace(e.target.data);
}
function httpStatusHandler(e:HTTPStatusEvent):void
{
trace("httpStatusHandler:" + e.status);
}
function securityErrorHandler(e:SecurityErrorEvent):void
{
trace("securityErrorHandler:" + e.text);
}
function ioErrorHandler(e:IOErrorEvent):void
{
trace("ioErrorHandler: " + e.text);
}
这篇关于如何在 Actionscript 3 中访问 REST 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文