C#实现UrlEncode (URL编码)

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

 

转载于:https://www.cnblogs.com/gengaixue/archive/2012/08/03/2621054.html

你可能感兴趣的:(C#实现UrlEncode (URL编码))