ASP中實現(xiàn)的URLEncode、URLDecode自定義函數(shù)
在做ajax中的post時,發(fā)現(xiàn)在服務器端取得數(shù)據(jù)時總是亂碼,網(wǎng)上看了些解決方法也搞不定,我post過去時是xml形式,由于亂碼服務器端xml也解析不了或出錯。于是在post前先把它編碼,到服務器端再解碼,這樣問題解決了,但是要是數(shù)據(jù)很大時估計會很影響速度。
雖然ASP中的request會自動解碼經(jīng)過url編碼的字符串,但是Request.BinaryRead(Request.TotalBytes)取得post數(shù)據(jù)時卻不會解碼,所以要進行解碼。
下面是我找到的一個ASP中server.urlencode函數(shù)的解碼函數(shù)
Function URLDecode(enStr)
dim deStr,strSpecial
dim c,i,v
deStr=""
strSpecial="!""#$%&'()*+,.-_/:;< =>?@[/]^`{|}~%"
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if inStr(strSpecial,chr(v))>0 then
deStr=deStr&chr(v)
i=i+2
else
v=eval("&h"+ Mid(enStr,i+1,2) + Mid(enStr,i+4,2))
deStr=deStr & chr(v)
i=i+5
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
End function
再附一個編碼函數(shù),這個與server.urlencode不一樣之處是:server.urlencode會將html或xml等標簽,如
也會進行編碼,而下面這個函數(shù)不會。我是用下面的進行編碼,再解碼,因為我用post時用xml的。
private Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00)/ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function
- ASP 時間函數(shù)及如何獲取服務器時間的寫法
- Asp Split函數(shù)之使用多個分割符的方法
- asp與js的類型轉(zhuǎn)換函數(shù)介紹
- asp中的Rnd 函數(shù)
- ASP轉(zhuǎn)換格林威治時間函數(shù)DateDiff()應用
- ASP移動文件函數(shù)movefile權限不足的替代方法
- asp實現(xiàn)獲取MSSQL數(shù)據(jù)庫表指定條件行數(shù)的函數(shù)
- asp中實現(xiàn)清除html的函數(shù)
- asp實現(xiàn)截取字符串函數(shù)
- ASP實現(xiàn)強制圖片下載函數(shù)
- ASP函數(shù)大全解析
相關文章
ASP網(wǎng)站出現(xiàn) msxml3.dll 錯誤 80072ee7 錯誤的解決方法
這兩天接到通知,說公司的一個網(wǎng)站訪問不了,經(jīng)訪問發(fā)現(xiàn)頁面提示如下錯誤2011-08-08非常好用的asp備份,還原SQL數(shù)據(jù)庫的代碼
用asp的朋友,可以用下面的代碼,實現(xiàn)mssql數(shù)據(jù)庫的備份還原操作2008-06-06ASP 支持中文的len(),left(),right()的函數(shù)代碼
在用ASP處理文字時。系統(tǒng)自帶的字符串長度檢測函數(shù)有時候也不是很好用。2010-05-05