在做ajax中的post時,發(fā)現(xiàn)在服務(wù)器端取得數(shù)據(jù)時總是亂碼,網(wǎng)上看了些解決方法也搞不定,我post過去時是xml形式,由于亂碼服務(wù)器端xml也解析不了或出錯。于是在post前先把它編碼,到服務(wù)器端再解碼,這樣問題解決了,但是要是數(shù)據(jù)很大時估計會很影響速度。
雖然ASP中的request會自動解碼經(jīng)過url編碼的字符串,但是Request.BinaryRead(Request.TotalBytes)取得post數(shù)據(jù)時卻不會解碼,所以要進行解碼。
下面是我找到的一個ASP中server.urlencode函數(shù)的解碼函數(shù)
復(fù)制代碼 代碼如下:
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=deStrchr(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=deStrc
end if
end if
next
URLDecode=deStr
End function
再附一個編碼函數(shù),這個與server.urlencode不一樣之處是:server.urlencode會將html或xml等標(biāo)簽,如
也會進行編碼,而下面這個函數(shù)不會。我是用下面的進行編碼,再解碼,因為我用post時用xml的。
復(fù)制代碼 代碼如下:
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ù)及如何獲取服務(wù)器時間的寫法
- Asp Split函數(shù)之使用多個分割符的方法
- asp與js的類型轉(zhuǎn)換函數(shù)介紹
- asp中的Rnd 函數(shù)
- ASP轉(zhuǎn)換格林威治時間函數(shù)DateDiff()應(yīng)用
- ASP移動文件函數(shù)movefile權(quán)限不足的替代方法
- asp實現(xiàn)獲取MSSQL數(shù)據(jù)庫表指定條件行數(shù)的函數(shù)
- asp中實現(xiàn)清除html的函數(shù)
- asp實現(xiàn)截取字符串函數(shù)
- ASP實現(xiàn)強制圖片下載函數(shù)
- ASP函數(shù)大全解析