国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

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

2024-05-04 11:10:00
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了ASP中只有UrlEncode,沒有Urldecode問題的解決方法? ,需要的朋友可以參考下

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

UrlEncode的原理其實很簡單,就是將特殊字符轉換成16進制ASC碼值,那么譯碼函數就只要將16進制ASC轉回對應的字符就OK了。

 

 
  1. Function URLDecode(enStr) 'URL解碼函數  
  2. dim deStr  
  3. dim c,i,v  
  4. deStr="" 
  5. for i=1 to len(enStr)  
  6. c=Mid(enStr,i,1)  
  7. if c="%" then  
  8. v=eval("&h"+Mid(enStr,i+1,2))  
  9. if v<128 then  
  10. deStr=deStr&chr(v)  
  11. i=i+2  
  12. else  
  13. if isvalidhex(mid(enstr,i,3)) then  
  14. if isvalidhex(mid(enstr,i+3,3)) then  
  15. v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))  
  16. deStr=deStr&chr(v)  
  17. i=i+5  
  18. else  
  19. v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))  
  20. deStr=deStr&chr(v)  
  21. i=i+3  
  22. end if  
  23. else  
  24. destr=destr&c  
  25. end if  
  26. end if  
  27. else  
  28. if c="+" then  
  29. deStr=deStr&" " 
  30. else  
  31. deStr=deStr&c  
  32. end if  
  33. end if  
  34. next  
  35. URLDecode=deStr  
  36. end function  
  37.  
  38. function isvalidhex(str)  
  39. isvalidhex=true  
  40. str=ucase(str)  
  41. if len(str)<>3 then isvalidhex=false:exit function  
  42. if left(str,1)<>"%" then isvalidhex=false:exit function  
  43. c=mid(str,2,1)  
  44. if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function  
  45. c=mid(str,3,1)  
  46. if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function  
  47. end function 

經測試gb312格式的asp使用沒有問題。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 社会| 运城市| 塔河县| 太湖县| 商南县| 泸州市| 屏山县| 罗源县| 合山市| 丰镇市| 会理县| 赞皇县| 和龙市| 日照市| 万源市| 柘荣县| 葵青区| 祁门县| 贵德县| 苏尼特右旗| 十堰市| 北安市| 金塔县| 汶上县| 威宁| 郑州市| 宁城县| 保靖县| 合作市| 隆化县| 东乡县| 潮州市| 称多县| 天门市| 金寨县| 房产| 望江县| 弥勒县| 修水县| 胶州市| 双峰县|