ASP Request

Request 对象

当浏览器向服务器请求页面时,这个行为就被称为一个 request(请求)。Request 对象用于从用户那里获取信息。它的集合、属性和方法描述如下:

ClientCertificate集合

ClientCertificate集合包含了存储在客户证书中的所有的字段值。

Cookies集合

Cookies集合包含了 HTTP 请求中发送的所有的 cookie 值。

(具体可翻阅上一章节)

Form集合

Form 集合用于从使用 POST 方法的表单获取表单元素的值。

语法

Request.Form(element)[(index)|.Count]

参数说明:

element--必需。表单元素的名称,此集合从中取回值。

index--可选。规定一个参数的多个值中的一个。从1到Request.Form(parameter).Count。

实例

您可以遍历表单请求中的所有值。假设用户通过为 color 元素指定两个值来填写了表单 - Blue 和 Green - 您能够这样取回这些值:

<%
for i=1 to Request.Form("color").Count
  Response.Write(Request.Form("color")(i) & "<br>")
next
%>

输出:
Blue
Green

QueryString 集合

QueryString 集合用于取回 HTTP 查询字符串中的变量值。

HTTP 查询字符串是由问号(?)之后的值规定的,比如:

<a href= "test.html?txt=this is a query string test">Link with a query string</a>

上面的代码可生成一个名为 txt 且值为 "this is a query string test"的变量。

查询字符串同样可以通过表单提交来生成,或者通过用户在浏览器的地址栏中输入查询。

注意:如果您需要 post 大量的数据(超过 100kb),就不能使用 Request.QueryString。

语法

Request.QueryString(variable)[(index)|.Count]

参数说明:

variable--必需。在HTTP查询字符串中要取回的变量名称。

index--可选。为一个变量规定多个值之一。从1到Request.QueryString(variable).Count。

实例

遍历查询字符串中所有变量 n 的值:

假设,这是被送出的请求:

https://www.imooc.com/test/names.html?n=John&n=Susan

而 names.asp 包含以下代码:

<%
for i=1 to Request.QueryString("n").Count
  Response.Write(Request.QueryString("n")(i) & "<br>")
next
%>

文件 names.asp 会显示出:

John
Susan

ServerVariables 集合

语法

Request.ServerVariables (server_variable)

参数说明:server_variable--必需。要取回的服务器变量的名称。

服务器变量

variable说明
ALL_HTTPReturns all HTTP headers sent by the client. Always prefixed      with HTTP_ and capitalized
ALL_RAWReturns all headers in raw form
APPL_MD_PATHReturns the meta base path for the application for the ISAPI  DLL
APPL_PHYSICAL_PATHReturns the physical path corresponding to the meta      base path
AUTH_PASSWORDReturns the value entered in the client's authentication dialog
AUTH_TYPEThe authentication method that the server uses to validate users
AUTH_USERReturns the raw authenticated user name
CERT_COOKIEReturns the unique ID for client certificate as a string
CERT_FLAGSbit0 is set to 1 if the client certificate is present and bit1 is set to 1 if the cCertification authority of the client certificate is  not valid
CERT_ISSUERReturns the issuer field of the client certificate
CERT_KEYSIZEReturns the number of bits in Secure Sockets Layer connection key  size
CERT_SECRETKEYSIZEReturns the number of bits in server certificate private key
CERT_SERIALNUMBERReturns the serial number field of the client certificate
CERT_SERVER_ISSUERReturns the issuer field of the server certificate
CERT_SERVER_SUBJECTReturns the subject field of the server certificate
CERT_SUBJECTReturns the subject field of the client certificate
CONTENT_LENGTHReturns the length of the content as sent by the client
CONTENT_TYPEReturns the data type of the content
GATEWAY_INTERFACEReturns the revision of the CGI specification used by the  server
HTTP_<HeaderName>Returns the value stored in the header HeaderName
HTTP_ACCEPTReturns the value of the Accept header
HTTP_ACCEPT_LANGUAGEReturns a string describing the language to use for displaying  content
HTTP_COOKIEReturns the cookie string included with the request
HTTP_REFERERReturns a string containing the URL of the page that referred the request to the current page using an <a> tag. If the page is redirected, HTTP_REFERER is empty
HTTP_USER_AGENTReturns a string describing the browser that sent the request
HTTPSReturns ON if the request came in through secure channel or OFF if the request  came in through a non-secure channel
HTTPS_KEYSIZEReturns the number of bits in Secure Sockets Layer connection key  size
HTTPS_SECRETKEYSIZEReturns the number of bits in server certificate private key
HTTPS_SERVER_ISSUERReturns the issuer field of the server certificate
HTTPS_SERVER_SUBJECTReturns the subject field of the server certificate
INSTANCE_IDThe ID for the IIS instance in text format
INSTANCE_META_PATHThe meta base path for the instance of IIS that responds to the  request
LOCAL_ADDRReturns the server address on which the request came in
LOGON_USERReturns the Windows account that the user is logged into
PATH_INFOReturns extra path information as given by the client
PATH_TRANSLATEDA translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical  mapping
QUERY_STRINGReturns the query information stored in the string following the question mark (?) in the HTTP  request
REMOTE_ADDRReturns the IP address of the remote host making the request
REMOTE_HOSTReturns the name of the host making the request
REMOTE_USERReturns an unmapped user-name string sent in by the user
REQUEST_METHODReturns the method used to make the request
SCRIPT_NAMEReturns a virtual path to the script being executed
SERVER_NAMEReturns the server's host name, DNS alias, or IP address as it would appear in self-referencing  URLs
SERVER_PORTReturns the port number to which the request was sent
SERVER_PORT_SECUREReturns a string that contains 0 or 1. If the request is being handled on the secure port,  it will be 1. Otherwise, it will be 0
SERVER_PROTOCOLReturns the name and revision of the request information  protocol
SERVER_SOFTWAREReturns the name and version of the server software that answers the request and runs the  gateway
URLReturns the base portion of the URL

实例

您可以像这样来循环遍历所有的服务器变量:

<%
for each x in Request.ServerVariables
  response.write(x & "<br>")
next
%>

下面的实例演示了如何查明访问者浏览器的类型、IP 地址等等:

<html>
<body>
<p>
<b>You are browsing this site with:</b>
<%Response.Write(Request.ServerVariables("http_user_agent"))%>
</p>
<p>
<b>Your IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_addr"))%>
</p>
<p>
<b>The DNS lookup of the IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_host"))%>
</p>
<p>
<b>The method used to call the page:</b>
<%Response.Write(Request.ServerVariables("request_method"))%>
</p>
<p>
<b>The server's domain name:</b>
<%Response.Write(Request.ServerVariables("server_name"))%>
</p>
<p>
<b>The server's port:</b>
<%Response.Write(Request.ServerVariables("server_port"))%>
</p>
<p>
<b>The server's software:</b>
<%Response.Write(Request.ServerVariables("server_software"))%>
</p>
</body>
</html>

TotalBytes 属性

TotalBytes 属性是一个只读的属性,可返回在客户端发送的请求正文中的字节总数。

语法

varbytes=Request.Totalbytes

实例

下面的代码把一个变量设置为请求正文发送的字节总数:

<%
dim a
a=Request.TotalBytes
%>

BinaryRead 方法

BinaryRead 方法用于获取作为 POST 请求的部分从客户机发送到服务器的数据。它将在一个安全的数组中存储数据,数组用于存储有关维数及尺寸范围的信息。

注意:请在调用 BinaryRead 之后调用 Request.Form,否则会引起错误。

语法

Request.BinaryRead(count)

参数说明:count--必需。规定要从客户机读取多少字节。

实例

下面的例子使用 BinaryRead 方法把一个请求的内容放入了一个安全的数组:

<%
dim a,b
a=Request.TotalBytes
b=Request.BinaryRead(a)
%>  


本内容均来自互联网,仅供参考,如有侵权请及时通知本站予以删除。邮箱:wiki#imooc.com (#改成@)

意见反馈 帮助中心 APP下载
官方微信