主頁 > 知識(shí)庫 > ASP中只有UrlEncode,沒有Urldecode問題的解決方法?

ASP中只有UrlEncode,沒有Urldecode問題的解決方法?

熱門標(biāo)簽:Mysql連接數(shù)設(shè)置 服務(wù)器配置 電子圍欄 Linux服務(wù)器 銀行業(yè)務(wù) 阿里云 科大訊飛語音識(shí)別系統(tǒng) 團(tuán)購網(wǎng)站

在ASP中傳遞參數(shù)時(shí)有一個(gè)很有用的系統(tǒng)函數(shù)Server.UrlEncode,可以將一些非字母數(shù)字的特殊符號(hào)轉(zhuǎn)換成標(biāo)準(zhǔn)URL編碼(其實(shí)就是16進(jìn)制ASC碼),這樣就解決了參數(shù)傳遞問題,然后我以為也提供了Server.UrlDecode,但使用后卻發(fā)現(xiàn)程序報(bào)錯(cuò),原來系統(tǒng)并沒有提供這個(gè)我想象中的解碼函數(shù)。怎幺辦,自己動(dòng)手吧。

UrlEncode的原理其實(shí)很簡單,就是將特殊字符轉(zhuǎn)換成16進(jìn)制ASC碼值,那么譯碼函數(shù)就只要將16進(jìn)制ASC轉(zhuǎn)回對(duì)應(yīng)的字符就OK了。

Function URLDecode(enStr)          'URL解碼函數(shù) 
 dim deStr 
 dim c,i,v 
 deStr="" 
 for i=1 to len(enStr) 
   c=Mid(enStr,i,1) 
   if c="%" then 
     v=eval("h"+Mid(enStr,i+1,2)) 
     if v128 then 
       deStr=deStrchr(v) 
       i=i+2 
     else 
       if isvalidhex(mid(enstr,i,3)) then 
         if isvalidhex(mid(enstr,i+3,3)) then 
           v=eval("h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2)) 
           deStr=deStrchr(v) 
           i=i+5 
         else 
           v=eval("h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1))))) 
           deStr=deStrchr(v) 
           i=i+3 
         end if 
       else 
         destr=destrc 
       end if 
     end if 
   else 
     if c="+" then 
       deStr=deStr" " 
     else 
       deStr=deStrc 
     end if 
   end if 
 next 
 URLDecode=deStr 
end function 
 
function isvalidhex(str) 
 isvalidhex=true 
 str=ucase(str) 
 if len(str)>3 then isvalidhex=false:exit function 
 if left(str,1)>"%" then isvalidhex=false:exit function 
 c=mid(str,2,1) 
 if not (((c>="0") and (c="9")) or ((c>="A") and (c="Z"))) then isvalidhex=false:exit function 
 c=mid(str,3,1) 
 if not (((c>="0") and (c="9")) or ((c>="A") and (c="Z"))) then isvalidhex=false:exit function 
end function

經(jīng)測(cè)試gb312格式的asp使用沒有問題。

您可能感興趣的文章:
  • ASP中實(shí)現(xiàn)的URLEncode、URLDecode自定義函數(shù)
  • ASP的URLDecode函數(shù)URLEncode解碼函數(shù)
  • 用ASP應(yīng)用程序?qū)崿F(xiàn)自己的UrlDeCode

標(biāo)簽:棗莊 廣元 江蘇 大理 衢州 衡水 蚌埠 萍鄉(xiāng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP中只有UrlEncode,沒有Urldecode問題的解決方法?》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266