예제 #1
0
        IEnumerator DownloadFileSizeHandler(string url, int timeout, Action <bool, int, int> done)
        {
            HeadHandler     handler = new HeadHandler();
            UnityWebRequest request = UnityWebRequest.Head(url);

            request.downloadHandler = handler;
            request.timeout         = timeout;
            request.chunkedTransfer = true;
            request.disposeDownloadHandlerOnDispose = true;
            yield return(request.Send());

            if (done != null)
            {
                done(request.responseCode == 200, (int)request.responseCode, handler.ContentLength);
            }
            request.Abort();
            request.Dispose();
        }
예제 #2
0
        IEnumerator DownloadFileSizeHandler()
        {
            HeadHandler     handler = new HeadHandler();
            UnityWebRequest request = UnityWebRequest.Head(mDownloadObj.url);

            request.downloadHandler = handler;
            request.timeout         = UnityDownloadManager.TIMEOUT;
            request.chunkedTransfer = true;
            request.disposeDownloadHandlerOnDispose = true;
            yield return(request.SendWebRequest());

            //Dictionary<string, string> dic = request.GetResponseHeaders();
            //foreach (var item in dic) Debug.Log(item.Key + "     " + item.Value);
            //item.Key:Content-Type  item.Value:video/mp4
            //item.Key:Content-Disposition  item.Value:inline; filename = "o_1d6hoeipu1bem1rdjvqtush1gu8l.mp4"; filename *= utf - 8' 'o_1d6hoeipu1bem1rdjvqtush1gu8l.mp4

            //设置文件名的后缀
            string content_Type = request.GetResponseHeader("Content-Type");

            string[] arr     = content_Type.Split('/');
            string   houzhui = string.Format(".{0}", arr[arr.Length - 1]);

            if (!mDownloadObj.fileName.Contains("."))
            {
                mDownloadObj.fileName += houzhui;
                Debug.Log("添加后缀:" + mDownloadObj.fileName);
            }

            if (mDownloadObj.OnGetFileSizeAction != null)
            {
                mDownloadObj.SetContentLength(handler.ContentLength);
                mDownloadObj.OnGetFileSizeAction((int)request.responseCode, mDownloadObj);//request.responseCode == 200 代表获取文件大小成功
            }
            request.Abort();
            request.Dispose();
        }