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 }