本文介绍了在经典ASP中设置HTTP_X_FORWARDED_FOR服务器变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Request.ServerVariables集合中设置HTTP_X_FORWARDED_FOR值.我正在尝试Fiddler(请参阅本文).

I need to set the HTTP_X_FORWARDED_FOR value in the Request.ServerVariables collection. I'm trying with Fiddler (see this article).

所以我设置了一个自定义HTTP请求:

So I set up a custom HTTP request:

GET http://myhost/ HTTP/1.1 http_x_forwarded_for: my.fake.ip.1, my.fake.ip.2 Host: myhost.

请求已正确执行.

但是当我调试代码时,Request.ServerVariables("HTTP_X_FORWARDED_FOR")为空.我哪里错了?提琴手是正确的工具吗?

But when I debug the code, the Request.ServerVariables("HTTP_X_FORWARDED_FOR") is empty.Where am I wrong?Is Fiddler the correct tool?

推荐答案

您要发送的标头应为x-forwarded-for. Request.ServerVariables正是它所说的服务器变量.它不仅包含请求中发送的http标头.

The header you are sending should be x-forwarded-for. The Request.ServerVariables are exactly what it says server variables. It does not just contain the http headers sent in the request.

将标头值放入服务器变量中时,IIS为标头名称基于 的变量创建一个名称,但不是逐字名称.它将所有字符转换为大写,将所有-替换为_,并将HTTP_的前缀添加到标头名称中以创建服务器变量名称.添加该前缀是为了防止人为标题使其他固定服务器变量名混用.

When placing the header values into server variables IIS creates a name for the variable that is based on the header name but is not the name verbatim. It converts all characters to uppercase, replaces all - with _ and adds the prefix of HTTP_ to header name to create a server variable name. The prefix is added to prevent arbitary headers aliasing other fixed server variable names.

这篇关于在经典ASP中设置HTTP_X_FORWARDED_FOR服务器变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:45