예제 #1
0
 protected HttpBase(string name, SuccessCallBack success, FailedCallBack failure, bool needUI = true)
 {
     m_EventName     = name;
     m_SuccessAction = success;
     m_FailureAction = failure;
     GameEntry.Event.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess);
     GameEntry.Event.Subscribe(WebRequestFailureEventArgs.EventId, OnWebRequestFailure);
     m_SerialId = needUI ? (int)GameEntry.UI.OpenUIForm(UIFormId.ConnectForm, this) : -1;
 }
예제 #2
0
    /// <summary>
    /// 发送HTTP请求
    /// </summary>
    /// <returns>HTTP引擎状态</returns>
    /// <param name="type">HTTP请求类型</param>
    /// <param name="url">服务器URL地址</param>
    /// <param name="success">请求成功回调函数</param>
    /// <param name="data">需要传递的数据</param>
    /// <param name="autoMask">是否自动开启操作屏蔽遮罩层</param>
    /// <param name="timeOut">请求超时秒数</param>
    public void SendRequest(HTTP_REQUEST_TYPE type, string url, SuccessCallBack success, string data = "", bool autoMask = true, float timeOut = 5.0f)
    {
        if (type == HTTP_REQUEST_TYPE.Post && data == "")
        {
#if UNITY_EDITOR
            Debug.LogError("使用POST方式请求服务器,data数据不能为空!");
#endif
            return;
        }

        if (_Processing)
        {
#if UNITY_EDITOR
            Debug.LogError("HTTP引擎正在请求服务器!");
#endif
            return;
        }

        Coroutiner.Start(
            _SendRequestCallback(type, url, success, data, autoMask, timeOut)
            );
    }
예제 #3
0
        public StudentSignInServer(int _sid, string _tel, int cdid, string cid, byte[] _photo, long _timestamp, SuccessCallBack success, FailedCallBack failure)
            : base(GlobalData.Server_StudentSigninTimestamp, success, failure)
        {
            m_HttpSendData = new StudentSignData(_sid, _timestamp, _tel);

            m_HttpByteData = _photo;
            m_HttpForm.Add("sid", _sid.ToString());
            m_HttpForm.Add("tel", _tel);
            m_HttpForm.Add("timestamp", _timestamp.ToString());
            m_HttpForm.Add("cdid", cdid.ToString());
            m_HttpForm.Add("cid", cid);
        }
예제 #4
0
 public GetDeviceWareInServer(int _id, SuccessCallBack success, FailedCallBack failure)
     : base(GlobalData.Server_GetDevicewareById, success, failure, false)
 {
     m_HttpSendData = new GetDeviceWareData(_id);
 }
예제 #5
0
 public HuaweiOnsuccessListener(SuccessCallBack <T> c)
 {
     CallBack = c;
 }
예제 #6
0
        public TeachSignInServer(int _teacher, string _tel, long _timestamp, int cdid, string cid, byte[] _photo, SuccessCallBack success, FailedCallBack failure)
            : base(GlobalData.Server_TeacherSigninTimestamp, success, failure)
        {
            m_HttpSendData = new TeachSignData(_teacher, _timestamp, _tel);

            m_HttpByteData = _photo;
            m_HttpForm.Add("teacher", _teacher.ToString());
            m_HttpForm.Add("tel", _tel);
            m_HttpForm.Add("timestamp", _timestamp.ToString());
            m_HttpForm.Add("cdid", cdid.ToString());
            m_HttpForm.Add("cid", cid);
        }
예제 #7
0
 public LocationSuccessListener(SuccessCallBack c)
 {
     CallBack = c;
 }
예제 #8
0
 public HmsSuccessListener(SuccessCallBack <T> c)
 {
     CallBack = c;
 }
예제 #9
0
 public QueryCoursewareInServer(long _time, string _classesId, SuccessCallBack success, FailedCallBack failure)
     : base(GlobalData.Server_GetCoursewareDailyByClassestime, success, failure, false)
 {
     m_HttpSendData = new QueryCoursewareData(_time, _classesId);
 }
예제 #10
0
 public LoginServer(string _facetoken, string _auid, int _flag, SuccessCallBack success, FailedCallBack failure)
     : base(GlobalData.Server_Getuserbyfacetoken, success, failure)
 {
     m_HttpSendData = new LoginData(_facetoken, _auid, _flag);
 }
예제 #11
0
    /// <summary>
    /// 通过协同发送异步HTTP请求
    /// </summary>
    /// <returns>HTTP请求协同</returns>
    /// <param name="request">HTTP请求数据</param>
    private IEnumerator _SendRequestCallback(HTTP_REQUEST_TYPE type, string url, SuccessCallBack success, string data, bool autoMask, float timeOut)
    {
        _Processing = true;

        //if(autoMask)
        //{
        //    UIDispatcher.WaitMask(true);
        //}

#if UNITY_EDITOR
        string debug = "URL地址:" + url + "\n";
        debug += "数据:" + data + "\n";
        DateTime debugTime = DateTime.UtcNow;
#endif

        //判断请求类型,生成请求头
        if (type == HTTP_REQUEST_TYPE.Get)
        {
            _WWW = new WWW(url + (data != "" ? ("?" + data) : ""));
        }
        else
        {
            _WWW = new WWW(
                url,
                System.Text.UTF8Encoding.UTF8.GetBytes(data),
                new Dictionary <string, string>()
            {
                { "Content-Type", "application/json; charset=utf-8" }
            }
                );
        }

        //设置HTTP请求过期时间
        //TimeClock.One.New(
        //    "HttpEngineTimeOut",
        //    timeOut,
        //    delegate
        //    {
        //        _WWW.Dispose();
        //    }
        //);

        yield return(_WWW);

#if UNITY_EDITOR
        debug += "消耗时间:" + (DateTime.UtcNow - debugTime).TotalMilliseconds / 1000 + "秒\n";
#endif

        _Processing = false;

        //if (autoMask)
        //{
        //    UIDispatcher.WaitMask(false);
        //}

        bool haveError = false;
        bool isTimeOut = false;

        try
        {
            haveError = _WWW.error != null;
            //TimeClock.One.Cancel("HttpEngineTimeOut", false);
        }
        catch
        {
            //UIMessageBox.Alert(
            //    "请求超时,是否重试?",
            //    delegate
            //    {
            //        HttpEngine.One().SendRequest(
            //            type,
            //            url,
            //            success,
            //            data,
            //            autoMask,
            //            timeOut
            //        );
            //    },
            //    false,
            //    "网络错误"
            //);
            isTimeOut = true;
        }

        if (!isTimeOut)
        {
#if UNITY_EDITOR
            if (haveError)
            {
                Debug.LogError(debug = "服务器错误" + _WWW.error + "!" + debug + "\n");
            }
            else
            {
                Debug.Log(debug = "请求成功!" + debug + "服务器返回值:" + _WWW.text + "\n");
            }
#endif

            if (haveError)
            {
                //UIMessageBox.Alert(
                //    "通讯错误,是否重试?",
                //    delegate
                //    {
                //        HttpEngine.One().SendRequest(
                //            type,
                //            url,
                //            success,
                //            data,
                //            autoMask,
                //            timeOut
                //        );
                //    },
                //    false,
                //    "网络错误"
                //);
                _WWW.Dispose();
            }
            else
            {
                string serverData = _WWW.text;
                _WWW.Dispose();
                success(serverData);
            }
        }
#if UNITY_EDITOR
        else
        {
            Debug.LogError(debug = "服务器响应超时!" + debug);
        }
#endif
    }
 public UpdateClassDailyEndtimeInServer(int _id, SuccessCallBack success, FailedCallBack failure)
     : base(GlobalData.Server_UpdateClassDailyEndtime, success, failure)
 {
     m_HttpSendData = new UpdateClassDailyEndtimeData(_id);
 }
예제 #13
0
파일: Class1.cs 프로젝트: redwyre/MegaApi
 public Command(string command, SuccessCallBack successCallBack = null, ErrorCallBack errorCallBack = null)
 {
     _command = command;
     _successCallBack = successCallBack;
     _errorCallBack = errorCallBack;
 }