• egret http协议封装使用


    http协议:

    创建 HttpHandler类

    class HttpHandler
    {
        constructor()
        {
            
        }
    
        public static sendMsgCallBack(URL:string, param:string, callback:Function, method:string, thisObj:any):void
        {
    
            var loader:egret.URLLoader = new egret.URLLoader();
            loader.dataFormat = egret.URLLoaderDataFormat.TEXT;
            var request:egret.URLRequest = new egret.URLRequest(URL);
            request.method = method;
            request.data = new egret.URLVariables(param);
            loader.load(request);
    
            loader.addEventListener(egret.Event.COMPLETE, function(event:egret.Event)
            {
                var loader:egret.URLLoader = <egret.URLLoader>event.target;
                var data:egret.URLVariables = loader.data;
                Global.consoleLog(data.toString());
                var obj:any = JSON.parse(data.toString());
                if(thisObj != null)
                    callback.call(thisObj, obj);
            }, this);
    
            Global.consoleLog("URL: " + URL + " param:" + param)
        }
    }

    调用HttpHandler.sendMsgCallBack

     HttpHandler.sendMsgCallBack("https://test.baidu.cn/api.php", "param=" + JSON.stringify(param),
                                    this.recordClientListCallback, egret.URLRequestMethod.POST, this);

    响应调用函数

            private recordClientListCallback(obj: any): void {
                    if (obj.error_code == 0) {
                            成功
                    }
                    else {
                            EffectUtils.showTips("用户不存在", 5, false);
                    }
            }    
    

      

    山重水复疑无路,柳暗花明又一村! 专注填坑,少走弯路!
  • 相关阅读:
    行转列
    multipath 安装配置
    网卡绑定
    numa对MySQL多实例性能影响
    Fatal NI connect error 12170
    REVOKE DBA权限要小心
    Oracle 数据库整理表碎片
    listagg 函数
    10046 事件补充
    tkprof 解释
  • 原文地址:https://www.cnblogs.com/mqflive81/p/12170073.html
Copyright © 2020-2023  润新知