/// <summary> /// Begins the Http request /// </summary> /// <param name="url"></param> /// <returns></returns> public HttpTask GetAsync(string url) { var state = new HttpTask { Status = TaskStatus.Running, }; TaskManager.StartRoutine(GetAsync(state, url)); return state; }
/// <summary> /// Begins the Http request /// </summary> /// <param name="url"></param> /// <returns></returns> public HttpTask GetAsync(string url) { var state = new HttpTask { Status = TaskStatus.Running, }; TaskManager.StartRoutine(GetAsync(state, url)); return(state); }
IEnumerator PostAsync(HttpTask task, string url, string content) { if (!Headers.ContainsKey("Accept")) { Headers.Add("Accept", Accept); } if (!Headers.ContainsKey("Content-Type")) { Headers.Add("Content-Type", ContentType); } WWW www; try { www = new WWW(url, content == null ? new byte[1] : Encoding.UTF8.GetBytes(content), Headers); } catch (Exception ex) { Debug.LogException(ex); task.Exception = ex; task.Status = TaskStatus.Faulted; yield break; } if (!www.isDone) { TaskManager.StartRoutine(StartTimeout(www, Timeout)); yield return(www); } if (_disposed.Contains(www)) { task.StatusCode = HttpStatusCode.RequestTimeout; task.Exception = new Exception("Request timed out"); task.Status = TaskStatus.Faulted; _disposed.Remove(www); yield break; } task.StatusCode = GetCode(www); if (!string.IsNullOrEmpty(www.error)) { task.Exception = new Exception(www.error); task.Status = TaskStatus.Faulted; } else { task.Content = www.text; task.Status = TaskStatus.Success; } }
/// <summary> /// Begins the Http request /// </summary> /// <param name="url"></param> /// <param name="content"></param> /// <returns></returns> public HttpTask PostAsync(string url, string content) { var state = new HttpTask { Status = TaskStatus.Running, }; TaskManager.StartRoutine(PostAsync(state, url, content)); return(state); }
IEnumerator GetAsync(HttpTask task, string url) { WWW www; try { www = new WWW(url); } catch (Exception ex) { Debug.LogException(ex); task.Exception = ex; task.Status = TaskStatus.Faulted; yield break; } TaskManager.StartRoutine(StartTimeout(www, Timeout)); yield return(www); if (_disposed.Contains(www)) { task.StatusCode = HttpStatusCode.RequestTimeout; task.Exception = new Exception("Request timed out"); task.Status = TaskStatus.Faulted; _disposed.Remove(www); yield break; } task.StatusCode = GetCode(www); if (!string.IsNullOrEmpty(www.error)) { task.Exception = new Exception(www.error); task.Status = TaskStatus.Faulted; } else { task.Content = www.text; task.Status = TaskStatus.Success; } }
IEnumerator PostAsync(HttpTask task, string url, string content) { if (!Headers.ContainsKey("Accept")) Headers.Add("Accept", Accept); if (!Headers.ContainsKey("Content-Type")) Headers.Add("Content-Type", ContentType); WWW www; try { www = new WWW(url, content == null ? new byte[1] : Encoding.UTF8.GetBytes(content), Headers); } catch (Exception ex) { Debug.LogException(ex); task.Exception = ex; task.Status = TaskStatus.Faulted; yield break; } if (!www.isDone) { TaskManager.StartRoutine(StartTimeout(www, Timeout)); yield return www; } if (_disposed.Contains(www)) { task.StatusCode = HttpStatusCode.RequestTimeout; task.Exception = new Exception("Request timed out"); task.Status = TaskStatus.Faulted; _disposed.Remove(www); yield break; } task.StatusCode = GetCode(www); if (!string.IsNullOrEmpty(www.error)) { task.Exception = new Exception(www.error); task.Status = TaskStatus.Faulted; } else { task.Content = www.text; task.Status = TaskStatus.Success; } }
IEnumerator GetAsync(HttpTask task, string url) { WWW www; try { www = new WWW(url); } catch (Exception ex) { Debug.LogException(ex); task.Exception = ex; task.Status = TaskStatus.Faulted; yield break; } TaskManager.StartRoutine(StartTimeout(www, Timeout)); yield return www; if (_disposed.Contains(www)) { task.StatusCode = HttpStatusCode.RequestTimeout; task.Exception = new Exception("Request timed out"); task.Status = TaskStatus.Faulted; _disposed.Remove(www); yield break; } task.StatusCode = GetCode(www); if (!string.IsNullOrEmpty(www.error)) { task.Exception = new Exception(www.error); task.Status = TaskStatus.Faulted; } else { task.Content = www.text; task.Status = TaskStatus.Success; } }
/// <summary> /// Begins the Http request /// </summary> /// <param name="url"></param> /// <param name="content"></param> /// <returns></returns> public HttpTask PostAsync(string url, string content) { var state = new HttpTask { Status = TaskStatus.Running, }; TaskManager.StartRoutine(PostAsync(state, url, content)); return state; }