Пример #1
0
        /// <summary>
        /// 设置请求响应
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="code">Api状态码</param>
        /// <param name="description">api请求的描述</param>
        /// <returns></returns>
        public async Task <HttpResponseMessage> SetResponse(HttpRequestMessage request, ApiStatusCodeEnum code, string description)
        {
            string requestStr = await request.Content.ReadAsStringAsync();

            //记录日志用
            string controller = request.GetRouteData().Values["controller"].ToString();
            string action     = request.GetRouteData().Values["action"].ToString();

            if (string.IsNullOrEmpty(requestStr))
            {
                requestStr = request.RequestUri.ToString();
            }
            ResponseModel       model    = new ResponseModel(code, description);
            HttpResponseMessage response = request.CreateResponse(model.HttpStatusCode, model);
            TaskCompletionSource <HttpResponseMessage> tcs = new TaskCompletionSource <HttpResponseMessage>();

            tcs.SetResult(response);
            return(await tcs.Task);
        }
Пример #2
0
 public ResponseModel(ApiStatusCodeEnum status, string des)
 {
     this.ApiStatusCode  = status;
     this.Description    = des;
     this.HttpStatusCode = HttpStatusCode.OK;
 }