简单的RPC访问方式

package Config  
{   
    import flash.events.*;  
    import flash.net.*;  
      
    import mx.rpc.AsyncToken;  
    import mx.rpc.Responder;  
    import mx.rpc.events.FaultEvent;  
    import mx.rpc.events.ResultEvent;  
    import mx.rpc.http.HTTPService;  
 
    public class Connect extends EventDispatcher     
    {       
       // private static  var connect:Connect=null;   
       
        //连接的网址   
        public static  var myurl:String="http://localhost:8080/flash/receive.jsp";   
        public static  var liuyanurl:String="http://localhost:8080/web/Liuyan.jsp";   
        public static  var dailyurl:String="http://localhost:8080/web/Daily.jsp";  
        public static  var msgyurl:String="http://localhost:8080/web/Msg.jsp";  
        public static  var loginurl:String="http://localhost:8080/web/Login.jsp";  
        public static  var regurl:String="http://localhost:8080/web/Reg.jsp";  
        public static  var typeurl:String="http://localhost:8080/web/DailyType.jsp";  
          
        public function Connect()  
        {        
           
        }               
       
        public function sendMessage(para:URLVariables,myurl:String,type:String="POST",format:String="xml",proxy:Boolean=false):void   
        {    //设置发送数据的变量        
              
              var server:HTTPService=new HTTPService();  
              switch(type)  
              {   
                 case "POST":  
                 server.method="POST";  
                 break;  
                   
                 case "GET":  
                 server.method="GET";  
                 break;  
                   
              }  
              server.useProxy=proxy; //不启动代理服务  
                
              switch(format)  
              {  
                case "xml":  
                 server.resultFormat="xml";//设置返回数据的格式为xml     
                 case "text":  
                   server.resultFormat="text";//设置返回数据的格式为xml     
                break;  
              }  
              server.url=myurl;//指定发送的jsp页面  
              var responder:mx.rpc.Responder = new mx.rpc.Responder(onSuccess, onFault);  
              var call:AsyncToken =server.send(para);//发送数据  
              call.addResponder(responder);  
               
        }  
          
        private function onSuccess(event:ResultEvent):void 
        {  
           this.dispatchEvent(event);  
            
        }  
          private function onFault(event:FaultEvent):void 
        {  
           this.dispatchEvent(event);  
        }  
          
          
    }   

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值