简单的RPC访问方式

来源:互联网 发布:dnf怎么优化 编辑:程序博客网 时间:2024/06/05 05:43

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);  
        }  
          
          
    }   

 

原创粉丝点击