分享

在C#中使用server.UrlEncode() 方法

 aaie_ 2014-07-06
今天的蛛蛛 遇到的问题就是windows service 中没有办法用asp.net中Server.UrlEncode() 的方法 url没有办法转码 这个纠结啊!
办法如下: 尝试通过
控制台或Winform程序中如何编码或解码Server.URLEncode
2010年07月10日 星期六 23:03
在Asp.net中可以使用Server.HTMLEncode和Server.URLEncode 将文本或URL的特殊字符编码,
但在控制台或Winform程序中没有办法使用到这些方法,

解决办法:

右击项目==》添加引用==》.NET==》System.Web==》确定

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 "));

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多