ASP中只有UrlEncode,没有Urldecode问题的解决方法?
2015-05-22 11:08
549 查看
在ASP中传递参数时有一个很有用的系统函数Server.UrlEncode,可以将一些非字母数字的特殊符号转换成标准URL编码(其实就是16进制ASC码),这样就解决了参数传递问题,然后我以为也提供了Server.UrlDecode,但使用后却发现程序报错,原来系统并没有提供这个我想象中的解码函数。怎幺办,自己动手吧。
UrlEncode的原理其实很简单,就是将特殊字符转换成16进制ASC码值,那么译码函数就只要将16进制ASC转回对应的字符就OK了。
Function URLDecode(enStr) 'URL解碼函數 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
经测试gb312格式的asp使用没有问题。
您可能感兴趣的文章:
相关文章推荐
- [原创]关于“ASP.NET MVC Preview 5使用中,只有MVC Project模板,没有MVC Item 模板(MVC Item Template)的问题”解决
- 关于asp.net[没有相关的源行]错误的解决方法及IIS安装问题
- 关于asp.net[没有相关的源行]错误的解决方法及IIS安装问题
- ASP中只有UrlEncode,没有Urldecode?
- Android下Activity结束(finish())之后没有释放内存问题的解决方法
- 记一次ASP.NET无法连接数据库问题的解决方法(ORA-01017)
- 解决华为荣耀没有log开关。只有AP日志,cp日志的问题
- Android Webview中解决H5的音视频不能自动播放、只有声音没有图像的问题
- maven web 项目 没有spring-web.jar的问题解决方法
- 关于ASP.NET 无法连接MySql数据库的问题和解决方法
- LINUX 新增用户并解决没有补全和只有白色的问题
- linux 解决安装Nvidia驱动后,或者声音选项里只有HDMI,声卡没有声音的方法[集锦]
- 关于struts2 中action 属性没有 set 方法 依然会注入值的问题(解决)
- OLE:对象的类没有在注册数据库中注册 问题的三种解决方法
- Myeclipse中文件已经上传到server文件夹下,文件也没有被占用,可是页面中无法读取和使用问题的解决方法
- ASP.NET使用X509Certificate2出现一系列问题的解决方法
- C# ASP.NET 连接mysql数据库存入的中文乱码问题解决方法
- SAMBA配置 “你可能没有权限访问网络资源”的问题解决方法
- ASP.NET Core2.0 使用VSCode 版本1.13.1工具 开发控制台运行出现中文乱码问题及解决方法
- 远程桌面授权server没有提供许可证问题解决方法