C#实现Url编码和解码

来源:互联网 发布:阿里云dns解析 a记录 编辑:程序博客网 时间:2024/04/29 02:42

System.Web.HttpUtility.HtmlEncode(str);

System.Web.HttpUtility.HtmlDecode(str);

System.Web.HttpUtility.UrlEncode(str);

System.Web.HttpUtility.UrlDecode(str);


编码时可以指定编码的 
System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.Unicode); 
System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.UTF8); 
System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.GetEncoding( "GB2312 ")); 

解码也可以指定编码的 
System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.Unicode); 
System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.UTF8); 
System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.GetEncoding( "GB2312 "));