最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2015年05月22日 11:08:45   投稿:mdxy-dxy  
這篇文章主要介紹了ASP中只有UrlEncode,沒有Urldecode問題的解決方法? ,需要的朋友可以參考下

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

UrlEncode的原理其實很簡單,就是將特殊字符轉(zhuǎn)換成16進(jìn)制ASC碼值,那么譯碼函數(shù)就只要將16進(jìn)制ASC轉(zhuǎn)回對應(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 v<128 then 
       deStr=deStr&chr(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=deStr&chr(v) 
           i=i+5 
         else 
           v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1))))) 
           deStr=deStr&chr(v) 
           i=i+3 
         end if 
       else 
         destr=destr&c 
       end if 
     end if 
   else 
     if c="+" then 
       deStr=deStr&" " 
     else 
       deStr=deStr&c 
     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)測試gb312格式的asp使用沒有問題。

相關(guān)文章

最新評論

华坪县| 中宁县| 枞阳县| 板桥市| 木里| 包头市| 抚松县| 河南省| 东明县| 福海县| 凤台县| 巴林左旗| 宝兴县| 垦利县| 海林市| 依安县| 定襄县| 乌恰县| 灵川县| 清徐县| 四会市| 揭东县| 海丰县| 突泉县| 呈贡县| 温州市| 宜春市| 栾城县| 同仁县| 黄骅市| 桑日县| 醴陵市| 宁化县| 宝山区| 屏山县| 怀安县| 太仓市| 广德县| 通化县| 顺昌县| 岳西县|