示例#1
0
        /// <summary>
        /// 请求http
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        IEnumerator PostAsync(IPostData data, bool isReset = false)
        {
            if (netTimer.isTimeOut)
            {
                yield break;                        //超时退出请求
            }
            if (!isReset)
            {
                netTimer.StartTime();           //计时开始
            }
            string url = data.url;

            Debug.Log(">>:" + url);
            WWW www = new WWW(url);

            yield return(www);

            // yield break;    //测试超时

            Debug.Log("<< [" + data.ToString() + "]:" + www.text);
            netTimer.StopTime(); //计时停止

            if (netTimer.isTimeOut)
            {
                yield break;                        //超时退出请求,防止超时了还回来数据
            }
            string result = www.text;
            int    res    = -1;
            string errMsg = "";

            try
            {
                if (netParser == null)
                {
                    netParser = new NetworkDataParser();
                }
                res        = netParser.ParseData(result, out errMsg);
                serverTime = netParser.serverTime;
            }
            catch (Exception e)
            {
                Debug.LogWarning("HttpNetManager::PostAsync Error : commandId:[" + data.ToString() + "]error:" + e.Message + " Trace [" + e.StackTrace + "]");
                TriggerResponse(data, res, result, errMsg, true);
                yield break;
            }

            TriggerResponse(data, res, result, errMsg);

            if (res == NetworkDataParser.RESPONSE_CODE_RESULT_SUCCESS && queueDataGroup.NextSendRequest)
            { //进入下一组
                SendRequest();
            }
        }
示例#2
0
        /// <summary>
        /// 请求http
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        IEnumerator PostAsync(IPostData data, bool isReset = false)
        {
            if (netTimer.isTimeOut) yield break;    //超时退出请求

            if (!isReset) netTimer.StartTime(); //计时开始

            string url = data.url;
            Debug.Log(">>:" + url);
            WWW www = new WWW(url);
            yield return www;

            // yield break;    //测试超时

            Debug.Log("<< [" + data.ToString() + "]:" + www.text);
            netTimer.StopTime(); //计时停止

            if (netTimer.isTimeOut) yield break;    //超时退出请求,防止超时了还回来数据

            string result = www.text;
            int res = -1;
            string errMsg = "";
            try
            {
                if (netParser == null)
                {
                    netParser = new NetworkDataParser();
                }
                res = netParser.ParseData(result, out errMsg);
                serverTime = netParser.serverTime;
            }
            catch (Exception e)
            {
                Debug.LogWarning("HttpNetManager::PostAsync Error : commandId:[" + data.ToString() + "]error:" + e.Message + " Trace [" + e.StackTrace + "]");
                TriggerResponse(data, res, result, errMsg, true);
                yield break;
            }

            TriggerResponse(data, res, result, errMsg);

            if (res == NetworkDataParser.RESPONSE_CODE_RESULT_SUCCESS && queueDataGroup.NextSendRequest)
            { //进入下一组
                SendRequest();
            }
        }
示例#3
0
 /// <summary>
 /// 注入数据解析类,不注入默认使用框架里面的
 /// </summary>
 /// <param name="dataParse">Data parse.</param>
 public void RegisterNetworkDataParse(INetworkDataParse dataParse)
 {
     netParser = dataParse;
 }
示例#4
0
 /// <summary>
 /// 注入数据解析类,不注入默认使用框架里面的
 /// </summary>
 /// <param name="dataParse">Data parse.</param>
 public void RegisterNetworkDataParse(INetworkDataParse dataParse)
 {
     netParser = dataParse;
 }