asp教程中g(shù)et post提交表單區(qū)別有以下5點(diǎn)
Get和Post方式的區(qū)別有5點(diǎn)
1. get是從服務(wù)器上獲取數(shù)據(jù),post是向服務(wù)器傳送數(shù)據(jù)。
2. get是把參數(shù)數(shù)據(jù)隊(duì)列加到提交表單的ACTION屬性所指的URL中,值和表單內(nèi)各個(gè)字段一一對(duì)應(yīng),在URL中可以看到。post是通過HTTP post機(jī)制,將表單內(nèi)各個(gè)字段與其內(nèi)容放置在HTML HEADER內(nèi)一起傳送到ACTION屬性所指的URL地址。用戶看不到這個(gè)過程。
3. 對(duì)于get方式,服務(wù)器端用Request.QueryString獲取變量的值,對(duì)于post方式,服務(wù)器端用Request.Form獲取提交的數(shù)據(jù)。
4. get傳送的數(shù)據(jù)量較小,不能大于2KB。post傳送的數(shù)據(jù)量較大,一般被默認(rèn)為不受限制。但理論上,IIS4中最大量為80KB,IIS5中為100KB。
5. get安全性非常低,post安全性較高。
HTTP請(qǐng)求:GET與POST方法的區(qū)別
HTTP 定義了與服務(wù)器交互的不同方法,最基本的方法是 GET 和 POST。事實(shí)上 GET 適用于多數(shù)請(qǐng)求,而保留 POST 僅用于更新站點(diǎn)。根據(jù) HTTP 規(guī)范,GET 用于信息獲取,而且應(yīng)該是 安全的和冪等的。所謂安全的意味著該操作用于獲取信息而非修改信息。換句話說,GET 請(qǐng)求一般不應(yīng)產(chǎn)生副作用。冪等的意味著對(duì)同一 URL 的多個(gè)請(qǐng)求應(yīng)該返回同樣的結(jié)果。完整的定義并不像看起來那樣嚴(yán)格。從根本上講,其目標(biāo)是當(dāng)用戶打開一個(gè)鏈接時(shí),她可以確信從自身的角度來看沒有改變資源。 比如,新聞?wù)军c(diǎn)的頭版不斷更新。雖然第二次請(qǐng)求會(huì)返回不同的一批新聞,該操作仍然被認(rèn)為是安全的和冪等的,因?yàn)樗偸欠祷禺?dāng)前的新聞。反之亦然。POST 請(qǐng)求就不那么輕松了。POST 表示可能改變服務(wù)器上的資源的請(qǐng)求。仍然以新聞?wù)军c(diǎn)為例,讀者對(duì)文章的注解應(yīng)該通過 POST 請(qǐng)求實(shí)現(xiàn),因?yàn)樵谧⒔馓峤恢笳军c(diǎn)已經(jīng)不同了(比方說文章下面出現(xiàn)一條注解);
在FORM提交的時(shí)候,如果不指定Method,則默認(rèn)為GET請(qǐng)求,F(xiàn)orm中提交的數(shù)據(jù)將會(huì)附加在url之后,以?分開與url分開。字母數(shù)字字符原 樣發(fā)送,但空格轉(zhuǎn)換為“+“號(hào),其它符號(hào)轉(zhuǎn)換為%XX,其中XX為該符號(hào)以16進(jìn)制表示的ASCII(或ISO Latin-1)值。GET請(qǐng)求請(qǐng)?zhí)峤坏臄?shù)據(jù)放置在HTTP請(qǐng)求協(xié)議頭中,而POST提交的數(shù)據(jù)則放在實(shí)體數(shù)據(jù)中;GET方式提交的數(shù)據(jù)最多只能有 1024字節(jié),而POST則沒有此限制。
在表單里使用”post”和”get”有什么區(qū)別
在Form里面,可以使用post也可以使用get。它們都是method的合法取值。但是,post和get方法在使用上至少有兩點(diǎn)不同:
1、Get方法通過URL請(qǐng)求來傳遞用戶的輸入。Post方法通過另外的形式。
2、Get方式的提交你需要用Request.QueryString來取得變量的值,而Post方式提交時(shí),你必須通過Request.Form來訪問提交的內(nèi)容。
仔細(xì)研究下面的代碼。你可以運(yùn)行之來感受一下:
代碼
!--兩個(gè)Form只有Method屬性不同-->
FORM ACTION=“getpost.php教程” METHOD=“get”>
INPUT TYPE=“text” NAME=“Text” VALUE=“Hello World”>/INPUT>
INPUT TYPE=“submit” VALUE=“Method=Get”>/INPUT>
/FORM>
BR>
FORM ACTION=“getpost.php” METHOD=“post”>
INPUT TYPE=“text” NAME=“Text” VALUE=“Hello World”>/INPUT>
INPUT TYPE=“submit” VALUE=“Method=Post”>/INPUT>
/FORM>
? If Request.QueryString(“Text”) > ““ Then ?>
通過get方法傳遞來的字符串是: “B>?= Request.QueryString(“Text”) ?>/B>“BR>
? End If ?>
? If Request.Form(“Text”) > ““ Then ?>
通過Post方法傳遞來的字符串是: “B>?= Request.Form(“Text”) ?>/B>“BR>
? End If ?>
說明
把上面的代碼保存為getpost.asp,然后運(yùn)行,首先測試post方法,這時(shí)候,瀏覽器的url并沒有什么變化,返回的結(jié)果是:
通過Post方法傳遞來的字符串是: "Hello World"
然后測試用get方法提交,請(qǐng)注意,瀏覽器的url變成了:
http://localhost/general/form/getpost.php?Text=Hello+World
而返回的結(jié)果是:
通過get方法傳遞來的字符串是: "Hello World"
最后再通過post方法提交,瀏覽器的url還是:
http://localhost/general/form/getpost.php?Text=Hello+World
而返回的結(jié)果變成:
通過get方法傳遞來的字符串是: "Hello World"
通過Post方法傳遞來的字符串是: "Hello World"
提示
通過get方法提交數(shù)據(jù),可能會(huì)帶來安全性的問題。比如一個(gè)登陸頁面。當(dāng)通過get方法提交數(shù)據(jù)時(shí),用戶名和密碼將出現(xiàn)在URL上。如果:
1、 登陸頁面可以被瀏覽器緩存;
2、 其他人可以訪問客戶的這臺(tái)機(jī)器。
那么,別人即可以從瀏覽器的歷史記錄中,讀取到此客戶的賬號(hào)和密碼。所以,在某些情況下,get方法會(huì)帶來嚴(yán)重的安全性問題。
建議
在Form中,建議使用post方法。
看到這里腳本之家小編就為大家分享一個(gè)比較好的函數(shù)
'獲取參數(shù)值
Function getForm(element,ftype)
Select case ftype
case "get"
getForm=trim(request.QueryString(element))
case "post"
getForm=trim(request.Form(element))
case "both"
if isNul(request.QueryString(element)) then getForm=trim(request.Form(element)) else getForm=trim(request.QueryString(element))
End Select
getForm=replace(getForm,CHR(34),"quot;")
getForm=replace(getForm,CHR(39),"apos;")
End Function
使用方法
Title=getForm("Title", "post")
Title2=getForm("Title2", "post")
Author=getForm("Author", "post")
ContentSource=getForm("ContentSource", "post")
Content=getForm("Content", "post")
當(dāng)然為了安全后期也要加上安全檢測函數(shù)
'過濾參數(shù)
Function filterPara(byVal Para)
filterPara=preventSqlin(Checkxss(Para))
End Function
Function preventSqlin(content)
dim sqlStr,sqlArray,i,speStr
sqlStr="|>|%|%27|%16|'|''|;|*|and|exec|dbcc|alter|drop|insert|select|update|delete|count|master|truncate|char|declare|where|set|declare|mid|chr|union|from|{prefix}|top|user|/|\"
if isNul(content) then Exit Function
sqlArray=split(sqlStr,"|")
for i=lbound(sqlArray) to ubound(sqlArray)
if instr(lcase(content),sqlArray(i))>0 then
select case sqlArray(i)
case "":speStr="lt;"
case ">":speStr="gt;"
case "'","""":speStr="quot;"
'case ";":speStr=";"
case else:speStr=""
end select
content=replace(content,sqlArray(i),speStr)
end if
next
dim num
num=0
for i=lbound(sqlArray) to ubound(sqlArray)
if instr(lcase(content),sqlArray(i))>0 then
num=1
end if
next
if num=1 then
content=preventSqlin(content)
end if
preventSqlin=content
End Function
'過濾xss注入
Function checkxss(byVal ChkStr)
dim Str,re
Str = ChkStr
if IsNull(Str) then Checkxss = "" : Exit Function
Str = Replace(Str, "", "") : Str = Replace(Str, "'", "acute;") : Str = Replace(Str, """", "quot;") : Str = Replace(Str, "", "lt;") : Str = Replace(Str, ">", "gt;") : Str = Replace(Str, "/", "#47;") : Str = Replace(Str, "*", "#42;")
Set re = New RegExp
re.IgnoreCase = True : re.Global = True
re.Pattern = "(w)(here)" : Str = re.Replace(Str, "$1h#101;re")
re.Pattern = "(s)(elect)" : Str = re.Replace(Str, "$1el#101;ct")
re.Pattern = "(i)(nsert)" : Str = re.Replace(Str, "$1ns#101;rt")
re.Pattern = "(c)(reate)" : Str = re.Replace(Str, "$1r#101;ate")
re.Pattern = "(d)(rop)" : Str = re.Replace(Str, "$1ro#112;")
re.Pattern = "(a)(lter)" : Str = re.Replace(Str, "$1lt#101;r")
re.Pattern = "(d)(elete)" : Str = re.Replace(Str, "$1el#101;te")
re.Pattern = "(u)(pdate)" : Str = re.Replace(Str, "$1p#100;ate")
re.Pattern = "(\s)(or)" : Str = re.Replace(Str, "$1o#114;")
re.Pattern = "(java)(script)" : Str = re.Replace(Str, "$1scri#112;t")
re.Pattern = "(j)(script)" : Str = re.Replace(Str, "$1scri#112;t")
re.Pattern = "(vb)(script)" : Str = re.Replace(Str, "$1scri#112;t")
If Instr(Str, "expression") > 0 Then Str = Replace(Str, "expression", "e#173;xpression", 1, -1, 0)
Set re = Nothing
Checkxss = Str
End Function
一般來說內(nèi)容不用處理,要不容易得不到你想要的結(jié)果,其實(shí)內(nèi)容是有代碼的情況。