当前位置: 首页>>代码示例>>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;未经允许,请勿转载。