阅读的X转发,对于头 [英] Read X-Forwarded-For header

查看:141
本文介绍了阅读的X转发,对于头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要阅读 X-Forwarded-的价值对于 在请求标头值。

我试过

  HttpContext.Current.Request.Headers [X  - 转发,对于]斯普利特(新的char [] {','})FirstOrDefault()。

在C#。

还是需要通过分裂头:并采取第二个字符串?
我问这是因为,维基百科说


  

字段的一般格式为:
  的X转发-适用于:客户端1,proxy1,Proxy2将



解决方案

这是你得到的回报的格式为客户端1,proxy1,Proxy2将

所以,你用逗号分开它,并获得第一次看到你的客户端的IP地址。

I want to read the value of the X-Forwarded-For header value in a request.

I've tried

HttpContext.Current.Request.Headers["X-Forwarded-For"].Split(new char[] { ',' }).FirstOrDefault();  

in C#.

OR do I need to split the header by ":" and the take the second string? I am asking this because, Wikipedia says

The general format of the field is: X-Forwarded-For: client1, proxy1, proxy2

解决方案

The format that you get in return is client1, proxy1, proxy2

So you split it with the comma, and get the first to see the ip of your client.

这篇关于阅读的X转发,对于头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆