Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So you want to be able to look at the IP address of the client consuming the web service, from within the service?</p> <p>You could create a class like this that examines some of your server variables, some of which pull data from HTTP headers. I've found that just looking at HTTP_X_FORWARDED_FOR and REMOTE_ADDR does the trick (ex. in C#):</p> <pre><code>public class IP { public static String UserHostAddress { get { return HttpContext.Current.Request.UserHostAddress; } } public static String REMOTE_ADDR { get { return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } } public static String HTTP_X_FORWARDED_FOR { get { return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } } public static String HTTP_CLIENT_IP { get { return HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"]; } } public static String HTTP_X_FORWARDED { get { return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED"]; } } public static String HTTP_X_CLUSTER_CLIENT_IP { get { return HttpContext.Current.Request.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"]; } } public static String HTTP_FORWARDED_FOR { get { return HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED_FOR"]; } } public static String HTTP_FORWARDED { get { return HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED"]; } } public static String IP_ADDRESS { get { if (HTTP_X_FORWARDED_FOR != null) { return HTTP_X_FORWARDED_FOR; } return REMOTE_ADDR; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload