Is there a simple ActionScript class that fetches the content from a URL and returns it?
Is there a standard class that simply returns the response received from a URL given a URL?
Looking through the documentation, I found mx.servicetags.HTTPService, but I don't think it's what I'm looking for.
Update: The request is happening inside of a function and therefore that same function has to return the resu开发者_如何转开发lt. In other words, callbacks aren't going to work.
HTTPService
is specific to Flex. If you're looking for a pure actionscript-3 solution, use URLLoader with URLRequest
.
var ldr:URLLoader = new URLLoader();
ldr.addEventListener(Event.COMPLETE, onLoad);
ldr.load(new URLRequest(url));
function onLoad(e:Event):void
{
var loadedText:String = URLLoader(e.target).data;
trace(loadedText);
}
see sample code here: Load an external text/html file using ActionScript 3, sample code
精彩评论