/// <summary>
    /// 任务进行
    /// </summary>
    /// <param name="obj"></param>
    private static void TaskRun(object obj)
    {
        HTTPParamIndie param = obj as HTTPParamIndie;

        try
        {
            var        datas       = HTTPRequest.Get(param);
            FileStream fileStream  = datas.Item1;
            Stream     stream      = datas.Item2;
            long       fileLength  = datas.Item3;
            long       totalLength = datas.Item4;

            param.FileLength  = fileLength;
            param.TotalLength = totalLength;

            if (fileStream == null || stream == null)
            {
                StopTask(param);
                return;
            }

            if (!HTTPRequest.MD5Verfied(param.MD5, stream))
            {
                param.MD5FailCallBack?.Invoke();
                return;
            }

            byte[] buff = new byte[4096];
            int    len  = -1;
            while ((len = stream.Read(buff, 0, buff.Length)) > 0)
            {
                fileStream.Write(buff, 0, len);
                param.FileLength += len;
            }

            param.SuccessCallBack?.Invoke();

            StopTask(param);
            ContinueTask();
        }
        catch (Exception e)
        {
            if (param.CurRetryTime < param.RetryTime)
            {
                StopTask(param);
                StartTask(param);
                param.CurRetryTime++;
            }
            param.FailCallBack?.Invoke();
        }
    }
Esempio n. 2
0
    private void TestGetTimeout()
    {
        var request = new HTTPRequest();

        request.Get("http://111.111.111.111/", "get", (result, data) =>
        {
            if (result == false)
            {
                ColoredLogger.Log("Request failed: " + request.LastError, ColoredLogger.LogColor.Red);
            }
            m_PendingRequests.Remove(request);
        });
        //add to pending list
        m_PendingRequests.Add(request);
    }
Esempio n. 3
0
    private void TestGet()
    {
        var request = new HTTPRequest();

        request.Get("http://httpbin.org/", "get", (result, data) =>
        {
            if (result == true)
            {
                ColoredLogger.Log(Encoding.ASCII.GetString(data), ColoredLogger.LogColor.Green);
            }
            else
            {
                ColoredLogger.Log("Request failed: " + request.LastError, ColoredLogger.LogColor.Red);
            }
            m_PendingRequests.Remove(request);
        }, "name", "Hello", "age", 1);
        //add to pending list
        m_PendingRequests.Add(request);
    }
Esempio n. 4
0
 void Start()
 {
     m_Request = new HTTPRequest();
     m_Request.Get("http://m.ps123.net/sucai/UploadFiles/201103/2011032500295577.jpg", "", (result, data) =>
     {
         if (result == true)
         {
             Texture2D tex = new Texture2D(512, 512);
             if (ImageConversion.LoadImage(tex, data))
             {
                 Renderer.material.mainTexture = tex;
             }
             m_IsLoaded = true;
         }
         else
         {
             ColoredLogger.Log("failed load image: " + m_Request.LastError, ColoredLogger.LogColor.Red);
         }
         m_Request = null;
     });
 }