码迷,mamicode.com
首页 > Windows程序 > 详细

C#版winform实现UrlEncode

时间:2018-04-12 14:18:47      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:方法   box   控制   asp   nic   show   inf   for   特殊   

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


MessageBox.Show(System.Web.HttpUtility.UrlEncode(s,System.Text.Encoding.GetEncoding("GB2312")).ToUpper());

C#版winform实现UrlEncode

标签:方法   box   控制   asp   nic   show   inf   for   特殊   

原文地址:https://www.cnblogs.com/rainbowaab/p/8807399.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!