Esempio n. 1
0
 private static void BuildLogHeaders(HttpClient client, string token = "")
 {
     try
     {
         //登录信息
         //client.DefaultRequestHeaders.Authorization = CreateBasicCredentials(Ticket.LoginName, Ticket.Id, Ticket.ChineseName);
         //填充日志所需头
         if (HttpContext.Current != null)
         {
             var rid = HttpContext.Current.Items["__RIO_RequestID"] as string;
             if (rid == null)
             {
                 rid = Guid.NewGuid().ToString("N");
                 HttpContext.Current.Items["__RIO_RequestID"] = rid;
             }
             client.DefaultRequestHeaders.Add("appkey", "M44NJ725jfnbT7PLkLfarvhpD2DZ7"); //TODO 可配置 appkey
             client.DefaultRequestHeaders.Add("token", token);                            //TODO 可配置 appkey
             client.DefaultRequestHeaders.Add("X-RIO-RequestID", rid.UrlEncode());
             client.DefaultRequestHeaders.Add("X-RIO-UserIP", ClientHelper.GetIP().UrlEncode());
             client.DefaultRequestHeaders.Add("X-RIO-LoginUserName", HttpContext.Current.User.Identity.Name.UrlEncode());
             client.DefaultRequestHeaders.Add("X-RIO-UserName", HttpContext.Current.User.Identity.Name.UrlEncode());
             client.DefaultRequestHeaders.Add("X-RIO-Url", HttpContext.Current.Request.Url.AbsoluteUri.UrlEncode());
             client.DefaultRequestHeaders.Add("X-RIO-UserAgent", HttpContext.Current.Request.UserAgent.UrlEncode());
             var referrer = HttpContext.Current.Request.UrlReferrer == null ? "" : HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
             client.DefaultRequestHeaders.Add("X-RIO-Referer", referrer.UrlEncode());
         }
     }
     catch (Exception ex)
     {
         WebLog.Error(ex);
     }
 }
Esempio n. 2
0
 private static void VerifyStatus(HttpResponseMessage response)
 {
     if (!response.IsSuccessStatusCode)
     {
         if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
         {
             WebLog.Error(new UnauthorizedAccessException(response.ReasonPhrase, new Exception(response.RequestMessage.ToString())));
         }
         else
         {
             WebLog.Error(new HttpException((int)response.StatusCode, response.ReasonPhrase, new Exception(response.RequestMessage.ToString())));
         }
     }
 }