C#实现UrlEncode (URL编码)

 1 public static string UrlEncode(string str)
 2         {
 3             StringBuilder sb = new StringBuilder();
 4             byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str)
 5             for (int i = 0; i < byStr.Length; i++)
 6             {
 7                 sb.Append(@"%" + Convert.ToString(byStr[i], 16));
 8             }
 9             
10             return (sb.ToString());
11         }

 

posted @ 2018-11-20 10:42  编程世界里晃荡  阅读(14006)  评论(0编辑  收藏  举报