flex的HTTPService远程获取数据并保存为本地文件实例类
package{import flash.filesystem.File;import flash.filesystem.FileStream;import flash.filesystem.FileMode;import mx.rpc.events.FaultEvent;import mx.rpc.events.ResultEvent;import mx.rpc.http.HTTPService;public class DownMarkerXML{private var httpService:HTTPService;private var SAVEFILEURL:String = "E:\\dataTest\\hello.xml"; public function DownMarkerXML(){httpService = new HTTPService();}public function sendReq(strURL:String):void{httpService.url = strURL;httpService.useProxy = false;httpService.showBusyCursor = false;httpService.resultFormat = "e4x";httpService.method = "GET";httpService.addEventListener(ResultEvent.RESULT, loadAddr); //请求成功,返回了想要的数据httpService.addEventListener(FaultEvent.FAULT, myFaultErrorEvent); //请求失败,抛出异常httpService.send();}private function loadAddr(event:ResultEvent):void{if(httpService.lastResult != null){var markerXML:XML = XML(httpService.lastResult);writeData(markerXML);}}private function writeData(saveData:XML):void{ var fileStream:FileStream = new FileStream(); fileStream.open(new File(SAVEFILEURL), FileMode.WRITE); fileStream.writeUTFBytes(saveData); fileStream.close();}private function myFaultErrorEvent(myFaultEvent:FaultEvent):void{ //异常处理函数trace(myFaultEvent.message);}}}