国产探花免费观看_亚洲丰满少妇自慰呻吟_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使用沒有問題。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 陵川县| 措勤县| 横山县| 阿巴嘎旗| 巴南区| 淮阳县| 成都市| 宜昌市| 甘孜县| 禄劝| 阿尔山市| 翁源县| 师宗县| 资阳市| 曲阜市| 仁布县| 呈贡县| 宜宾市| 安新县| 萨嘎县| 务川| 陵川县| 双辽市| 东源县| 徐汇区| 哈密市| 张家川| 延边| 克山县| 清新县| 海伦市| 玛曲县| 台中市| 贵港市| 嘉义市| 南靖县| 通江县| 道孚县| 绥宁县| 南靖县| 阜城县|