本文整理匯總了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());
}