private HttpResponseMessage SendCompletion(HttpRequestMessage request, HttpResponseMessage response) { object obj2; if (ServerRoles.Instance.IsDevServer || ServerRoles.Instance.IsTestServer) { RequestInfo property = request.GetProperty <RequestInfo>(""); if ((property.ClientType == DevicePlatform.Android) || (property.ClientType == DevicePlatform.Ios)) { response.Headers.Add("t-imei", property.ImeiInfo.RealImei); response.Headers.Add("t_request_dt", property.ImeiInfo.GenerateTime.HasValue ? property.ImeiInfo.GenerateTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""); } } if (request.Properties.TryGetValue("eprepare-set-cookie", out obj2)) { IEnumerable <CookieHeaderValue> cookies = (IEnumerable <CookieHeaderValue>)obj2; response.Headers.AddCookies(cookies); } ObjectContent content = response.Content as ObjectContent; if (content == null) { return(response); } HttpError error = content.Value as HttpError; if (error == null) { return(response); } int logCode = new Random().Next(900000, 9999999); string exceptionMessage = error.ExceptionMessage; string stackTrace = error.StackTrace; if (string.IsNullOrEmpty(exceptionMessage) || string.IsNullOrEmpty(stackTrace)) { exceptionMessage = error.Message; stackTrace = error.MessageDetail; } QiuxunLogResult result = new QiuxunLogResult(-100, "未知错误,请联系管理员,日志码:" + logCode, logCode, exceptionMessage, stackTrace); LogHelper.WriteLog(string.Format("请求错误,日志码{0},地址:{1}\r\n{2}\r\n{3}", logCode, request.RequestUri, exceptionMessage, stackTrace)); //LogManager.GetLogger(string.IsNullOrEmpty(error.ExceptionType) ? "Default" : error.ExceptionType).ErrorFormat("请求错误,日志码{0},地址:{1}\r\n{2}\r\n{3}", logCode, request.RequestUri, exceptionMessage, stackTrace); return(request.CreateResponse <QiuxunLogResult>(response.StatusCode, result)); }
protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { RequestInfo requestInfo = request.GetProperty <RequestInfo>(""); if (requestInfo == null) { requestInfo = RequestHelper.BuildRequestInfo(request); request.AddProperty <RequestInfo>(requestInfo, ""); } return(base.SendAsync(request, cancellationToken).ContinueWith <HttpResponseMessage>(delegate(Task <HttpResponseMessage> task) { object obj2; InterfaceSetting property = request.GetProperty <InterfaceSetting>(""); if ((requestInfo.HttpMethod == HttpMethod.Options) || ((property != null) && property.DisableLog)) { return task.Result; } RequestLog log = RequestHelper.BuildRequestLog(request, requestInfo); HttpResponseMessage message = task.Result; string str = string.Empty; ObjectContent content = message.Content as ObjectContent; if (content != null) { QiuxunLogResult result = content.Value as QiuxunLogResult; if (result != null) { log.ApiStatus = result.LogCode; log.ApiDesc = result.LogDesc; log.ApiDescDetail = result.LogDescDetail; } else { ApiResult result2 = content.Value as ApiResult; if (result2 != null) { log.ApiStatus = result2.Code; log.ApiDesc = result2.Desc; if (((property != null) && property.IsRecordResponseData) && (result2.Code == 100)) { str = result2.ToJsonString(); } } } } if (request.Properties.TryGetValue("eprepare-set-cookie", out obj2)) { IEnumerable <CookieHeaderValue> enumerable = (IEnumerable <CookieHeaderValue>)obj2; foreach (CookieHeaderValue value2 in enumerable) { log.ResponseCookie = log.ResponseCookie + string.Format("{0}~", value2.ToString()); } if (log.ResponseCookie.Length > 0) { log.ResponseCookie = log.ResponseCookie.TrimEnd(new char[] { '~' }); } } log.HttpStatus = (int)message.StatusCode; if (this.allWebRequest) { RequestHelper.WriteAllWebRequestLog(log); return message; } if (((property != null) && property.IsRecordResponseData) && !string.IsNullOrEmpty(str)) { RequestHelper.WriteWebRequestLog(log, str); return message; } RequestHelper.WriteWebRequestLog(log, str); return message; })); }