當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpRequestMessage.GetClientIp方法代碼示例

本文整理匯總了C#中System.Net.Http.HttpRequestMessage.GetClientIp方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpRequestMessage.GetClientIp方法的具體用法?C# HttpRequestMessage.GetClientIp怎麽用?C# HttpRequestMessage.GetClientIp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Net.Http.HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.GetClientIp方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SendAsync

        protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            try
            {
                HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
                if (flipConnections.Contains(request.GetClientIp()) || bwConnections.Contains(request.GetClientIp()))
                {
                    System.Drawing.Imaging.ImageFormat fmt;
                    MediaTypeHeaderValue mediatype = response.Content.Headers.ContentType;
                    if (response.IsSuccessStatusCode && ImageFormat(mediatype, out fmt))
                    {
                        var streamin = await response.Content.ReadAsStreamAsync();

                        using (Bitmap bmp = new Bitmap(Image.FromStream(streamin)))
                        {
                            if(flipConnections.Contains(request.GetClientIp()))
                                bmp.RotateFlip(RotateFlipType.RotateNoneFlipXY);
                            if(bwConnections.Contains(request.GetClientIp()))
                                MakeBW(bmp);
                            var msout = new MemoryStream();
                            bmp.Save(msout, fmt);
                            msout.Position=0;
                            response.Content = new StreamContent(msout);
                            response.Content.Headers.ContentType = mediatype;
                        }
                    }
                }
                return response;
            }
            catch (Exception ex)
            {
                var response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
                return response;
            }
        }
開發者ID:ssardari,項目名稱:buskerproxy,代碼行數:35,代碼來源:ImageHandler.cs

示例2: LogResponse

 private static async System.Threading.Tasks.Task LogResponse(HttpRequestMessage request, HttpResponseMessage response, Stopwatch stopwatch)
 {
     string connection;
     if (connections.TryGetValue(request.GetClientIp(), out connection))
     {
         var loggingHubContext = GlobalHost.ConnectionManager.GetHubContext<LoggingHub>();
         await loggingHubContext.Clients.Client(connection).LogUrl(request.RequestUri.ToString());
     }
 }
開發者ID:philbritton,項目名稱:buskerproxy,代碼行數:9,代碼來源:LoggingHandler.cs

示例3: SendAsync

 protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     request.Headers.Add("X-Forwarded-For", request.GetClientIp());
     if (request.Method == HttpMethod.Get || request.Method == HttpMethod.Trace) request.Content = null;
     request.RequestUri = new Uri(request.RequestUri.ToString().Replace(":3002", "")); //comes through with the port for the proxy, rewrite to port 80
     request.Headers.AcceptEncoding.Clear();
     var responseMessage = await new HttpClient().SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
     responseMessage.Headers.TransferEncodingChunked = null; //throws an error on calls to WebApi results
     if (request.Method == HttpMethod.Head) responseMessage.Content = null;
     return responseMessage;
 }
開發者ID:D3-LucaPiombino,項目名稱:WebAPI-Proxy,代碼行數:11,代碼來源:ForwardProxyMessageHandler.cs

示例4: AddProxyRequestHeader

 private void AddProxyRequestHeader(HttpRequestMessage request)
 {
     //do the proxy forward header thang
     request.Headers.Add("X-Forwarded-For", request.GetClientIp());
 }
開發者ID:ssardari,項目名稱:buskerproxy,代碼行數:5,代碼來源:ProxyHandler.cs


注:本文中的System.Net.Http.HttpRequestMessage.GetClientIp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。