萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> ASP 程式設計

ASP Request.Form 處理 POST 表單資料教學

GET 與 POST 差異

Request.Form 集合專門處理 method="POST" 表單提交的資料。資料放在 HTTP 要求主體,不會出現在 URL,適合傳遞大量或敏感資料。

HTML 表單修改為 POST

<form method="POST" action="tizagPost.asp">
  Name <input type="text" name="Name" />
  Age <input type="text" name="Age" />
  <input type="submit" />
</form>

ASP 處理頁面 (tizagPost.asp)

<%
Dim name, age
name = Request.Form("Name")
age  = Request.Form("Age")
Response.Write("Name: " & name & "
") Response.Write("Age: " & age & "
") %>

注意事項

  • POST 要求需包含 Content-Type: application/x-www-form-urlencoded 或 multipart/form-data(檔案上傳)。
  • Request.Form 只能讀取一次(串流特性),若需多次使用請先存入變數。
  • 大量資料(> 100 KB)可能需調整 AspMaxRequestEntityAllowed (IIS Metabase)。
  • 同樣需注意字元編碼一致性,建議頁面統一 UTF-8。

同時支援 GET/POST 的通用寫法

<%
Dim name, age
name = Request("Name")   ' 同時查詢 QueryString、Form、Cookies、ServerVariables
age  = Request("Age")
%>

Request("key") 會依序搜尋 QueryString、Form、Cookies、ServerVariables,方便但效能稍差,建議明確指定集合。

copyright © 萬盛學電腦網 all rights reserved