ASP中實(shí)現(xiàn)的URLEncode、URLDecode自定義函數(shù)
在做ajax中的post時(shí),發(fā)現(xiàn)在服務(wù)器端取得數(shù)據(jù)時(shí)總是亂碼,網(wǎng)上看了些解決方法也搞不定,我post過(guò)去時(shí)是xml形式,由于亂碼服務(wù)器端xml也解析不了或出錯(cuò)。于是在post前先把它編碼,到服務(wù)器端再解碼,這樣問(wèn)題解決了,但是要是數(shù)據(jù)很大時(shí)估計(jì)會(huì)很影響速度。
雖然ASP中的request會(huì)自動(dòng)解碼經(jīng)過(guò)url編碼的字符串,但是Request.BinaryRead(Request.TotalBytes)取得post數(shù)據(jù)時(shí)卻不會(huì)解碼,所以要進(jìn)行解碼。
下面是我找到的一個(gè)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
再附一個(gè)編碼函數(shù),這個(gè)與server.urlencode不一樣之處是:server.urlencode會(huì)將html或xml等標(biāo)簽,如
也會(huì)進(jìn)行編碼,而下面這個(gè)函數(shù)不會(huì)。我是用下面的進(jìn)行編碼,再解碼,因?yàn)槲矣胮ost時(shí)用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í)間函數(shù)及如何獲取服務(wù)器時(shí)間的寫(xiě)法
- Asp Split函數(shù)之使用多個(gè)分割符的方法
- asp與js的類(lèi)型轉(zhuǎn)換函數(shù)介紹
- asp中的Rnd 函數(shù)
- ASP轉(zhuǎn)換格林威治時(shí)間函數(shù)DateDiff()應(yīng)用
- ASP移動(dòng)文件函數(shù)movefile權(quán)限不足的替代方法
- asp實(shí)現(xiàn)獲取MSSQL數(shù)據(jù)庫(kù)表指定條件行數(shù)的函數(shù)
- asp中實(shí)現(xiàn)清除html的函數(shù)
- asp實(shí)現(xiàn)截取字符串函數(shù)
- ASP實(shí)現(xiàn)強(qiáng)制圖片下載函數(shù)
- ASP函數(shù)大全解析
相關(guān)文章
ASP網(wǎng)站出現(xiàn) msxml3.dll 錯(cuò)誤 80072ee7 錯(cuò)誤的解決方法
這兩天接到通知,說(shuō)公司的一個(gè)網(wǎng)站訪問(wèn)不了,經(jīng)訪問(wèn)發(fā)現(xiàn)頁(yè)面提示如下錯(cuò)誤2011-08-08asp實(shí)現(xiàn)帶刷新功能的驗(yàn)證碼代碼
本文給大家分享的是一段使用asp實(shí)現(xiàn)的驗(yàn)證碼功能,而且是帶刷新的,代碼非常簡(jiǎn)潔,非常實(shí)用,有需要的小伙伴可以參考下。2015-05-05生成EAN13標(biāo)準(zhǔn)的條形碼的ASP代碼實(shí)例
生成EAN13標(biāo)準(zhǔn)的條形碼的ASP代碼實(shí)例...2007-10-10非常好用的asp備份,還原SQL數(shù)據(jù)庫(kù)的代碼
用asp的朋友,可以用下面的代碼,實(shí)現(xiàn)mssql數(shù)據(jù)庫(kù)的備份還原操作2008-06-06asp教程中g(shù)et post提交表單有5點(diǎn)區(qū)別
asp教程中g(shù)et post提交表單有5點(diǎn)區(qū)別分別以HTTP請(qǐng)求,表單兩者分別介紹,需要的朋友可以了解下2012-12-12ASP 支持中文的len(),left(),right()的函數(shù)代碼
在用ASP處理文字時(shí)。系統(tǒng)自帶的字符串長(zhǎng)度檢測(cè)函數(shù)有時(shí)候也不是很好用。2010-05-05