As3访问http和webService的类,HttpRequest

时间:2016-07-09 09:56:42
【文件属性】:

文件名称:As3访问http和webService的类,HttpRequest

文件大小:2KB

文件格式:AS

更新时间:2016-07-09 09:56:42

HttpRequest URLLoader WebService URLRequest

package Helper { /* HttpRequest类 power by Ak18.cn 2013-06-19 Get请示例子 var req:HttpRequest=new HttpRequest(); req.Get(url,completeHandler); Post请求例子 var par:URLVariables=new URLVariables(); par.theCityName="北京"; req.Post(url,par,completeHandler); */ import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.*; import flash.net.URLVariables; public class HttpRequest { private var loader:URLLoader;// private var callBack:Function;//回调函数 public function HttpRequest() { // } //简单的Get,参数可以拼在URL? public function Get(url:String,_returnMethod:Function):void { Submit(url,null,"get",_returnMethod); } //简单的Post,参数可以拼在URL? public function Post(url:String,vars:URLVariables,_returnMethod:Function):void { Submit(url,vars,"post",_returnMethod); } //提交请示函数 private function Submit(url:String,vars:URLVariables,method:String,_returnMethod:Function):void { //vars.theCityName = "上海"; //url="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=上海"; var Request:URLRequest = new URLRequest(url); Request.method=method; Request.data = vars; trace(vars); loader = new URLLoader(Request); callBack = _returnMethod; loader.addEventListener(Event.COMPLETE, completeHandler); } //查询完成时调用此函数 private function completeHandler(ev:Event):void{ trace(loader.data); callBack.call(null,loader.data); } } }


网友评论

  • 对初学者说,有用
  • 谢谢。 实例很好用~
  • 写的很基础 对于初学者来说很不错
  • 不错,谢谢。 能用的实例