// HTTP DOWNLOAD 异步 static public HttpRequester Download(string url, int range, string savePath, ProcessDelegate onProcess = null, RespDelegate onResponse = null) { HttpRequester reqInfo = new HttpRequester(url, range.ToString(), "GETF", savePath, onProcess, onResponse); reqInfo.Start(); return(reqInfo); }
// HTTP通讯 异步 static public HttpRequester SendRequest(string url, string para, string method, ProcessDelegate onProcess = null, RespDelegate onResponse = null) { HttpRequester reqInfo = new HttpRequester(url, para, method.ToUpper(), null, onProcess, onResponse); reqInfo.Start(); return(reqInfo); }
private IEnumerator CoroHttpDownload(string url, int range, string savePath, float timeout) { float time = Time.realtimeSinceStartup + timeout; float progress = 0; var httpReq = HttpRequester.Download(url, range, savePath); for (;;) { yield return(null); float realtimeSinceStartup = Time.realtimeSinceStartup; if (httpReq.progress == progress) { if (time < realtimeSinceStartup) { httpReq.error = (int)HttpStatusCode.RequestTimeout; break; } continue; } else { time = realtimeSinceStartup + timeout; } if (onHttpDL != null) { onHttpDL.Invoke(url, (uint)httpReq.current, (uint)httpReq.total, httpReq.error); } if (httpReq.isDone || httpReq.error != null) { break; } progress = httpReq.progress; } }