本文整理汇总了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;
}
}
示例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());
}
}
示例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;
}
示例4: AddProxyRequestHeader
private void AddProxyRequestHeader(HttpRequestMessage request)
{
//do the proxy forward header thang
request.Headers.Add("X-Forwarded-For", request.GetClientIp());
}