Resquest對象
發表時間:2023-08-16 來源:明輝站整理相關軟件相關文章人氣:
[摘要]Resquest對象代表由各客戶程序發往HTTP的請求報文。事實上,Request對象的功能是單向的,它只能接收客戶端Web頁面提交的數據,與Response對象的功能剛好相反。Resquest接收...
Resquest對象代表由各客戶程序發往HTTP的請求報文。事實上,Request對象的功能是單向的,它只能接收客戶端Web頁面提交的數據,與Response對象的功能剛好相反。
Resquest接收數據時通過兩個集合QueryString和Form來檢索表單的數據,具體用哪一個集合,取決于Web頁面提交數據的HTTP表單的Method屬性,當Method屬性值為“Get”時以QueryString,而Method屬性值為“Post”時以Form。當省略了具體的集合名稱時,ASP將以下面的順序來搜索集合:QueryString -> Form -> Cookie ->ServerVariables。
<html>
<head>
</head>
<body>
<form aciton="log.asp" method="Get" name="login">
<input type=text name=logid>
<input type=text name=password>
<input type=submit name=submit1 value="提交">
</form>
</body>
</html>
當數據提交到服務器端的log.asp文件后,在log.asp中使用Request對象得到用戶提交的數據,加以判斷用戶是否合法。log.asp文件如下:
<%
dim User
dim Passwd
User=Request.QueryString("logid")
Passwd=Request.QueryString("password")
if User="jeff" then
if Passwd="123456" then
Response.write "登錄成功!"
else
Response.write "密碼錯誤!"
end if
else
Response.write "用戶名錯誤!"
end if
%>
上面這個例子中Method屬性使用了Get方法,所以使用Request.QueryString接收數據,相反若Method屬性使用了Post方法,則使用Request.Form接收數據。
而ServerVariables集合可用于提供有關隨HTTP請求一起傳遞的頭信息,它的引用格式為:
Request.ServerVariables("關鍵字")
其中的“關鍵字有:
REMOTE_ADDR-> 可以知道客戶端的IP
URL-> 得到系統的URL路徑
PATH_TRANSLATED-> 當前Active Server Page的真實地址
HTTP_UA_OS -> 瀏覽器所在的操作系統