/// <summary> /// 以tag方式创建新对象 /// </summary> /// <returns></returns> public static ReturnResult NewWithTag(object tag) { ReturnResult result = new ReturnResult(); if (tag == null) { result.msg = "获取数据为空"; return(result); } if (tag is bool) { bool suc = (bool)tag; if (!suc) { result.msg = "操作失败"; return(result); } } result.tag = tag; result.code = 0; return(result); }
/// <summary> /// 向服务端GET请求数据 /// </summary> public static void GET(Action <bool, WebExceptionStatus, ReturnResult> resultFunc, Uri url) { if (!inited) { throw new Exception("WebTools未初始化"); } HttpWebRequest webRequest = WebRequest.CreateHttp(url); webRequest.Method = "GET"; SetBasicAuthorization(webRequest); webRequest.BeginGetResponse(y => { WebResponse response = null; bool suc = false; WebExceptionStatus status = WebExceptionStatus.Success; ReturnResult result = null; try { response = webRequest.EndGetResponse(y); suc = true; } catch (WebException ex) { status = ex.Status; } result = GetResultFromResponse(response); if (resultFunc != null) { resultFunc(suc, status, result); //调用回调方法 } result = null; }, null); }