前一段时间做了个WinfROm版本的web服务器,结果抓取到地址栏中的参数,是乱码,豁然间想到了用UrlEncode,失望的是没有,然后我在程序集中点引用,在.NETFramework中引用也没有如下图:
后来想了想那么我通过浏览来找,C盘Windows找到了下图:
哈哈,就这样问题解决了,Ok问题解决以后,
问题又来了
通过以下方式可以解决
System.Web.HttpUtility.HtmlEncode(str);
System.Web.HttpUtility.HtmlDecode(str);
System.Web.HttpUtility.UrlEncode(str);
System.Web.HttpUtility.UrlDecode(str);
编码后得到的字串和用Server.URLEncode编码得到的不一样,那边接收到的也是乱码??
编码时可以指定编码的,如
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 "));