双鱼座的天蝎

导航

js和C#中的编码和解码

同一个字符串,用URL编码和HTML编码,结果是完全不同的。

 

JS中的URL编码和解码。对 ASCII 字母和数字及以下特殊字符无效: - _ . ! ~ * ' ( ) ,/?:@&=+$#

encodeURI("http://www.w3school.com") //url编码
decodeURI("http%3A%2F%2Fwww.w3school.com.cn") //url解码

encodeURIComponent("http://www.w3school.com") //url编码,含+
decodeURIComponent("http%3A%2F%2Fwww.w3school.com.cn") //url解码,含+

 

JS中的HTML编码和解码。对 ASCII 字母和数字及以下特殊字符无效: - _ . ! ~ * ' ( )

escape("text") //html编码
unescape("text") //html解码

 

C#中的URL编码和解码

HttpUtility.UrlEncode("http://www.w3school.com") //url编码
HttpUtility.UrlDecode("http%3A%2F%2Fwww.w3school.com.cn") //url解码

 

C#中的HTML编码和解码

HttpUtility.HtmlEncode("text") //html编码
HttpUtility.HtmlDecode("text") //html解码

 

posted on 2014-12-04 10:01  双鱼座的天蝎  阅读(597)  评论(3编辑  收藏  举报