WinForm 下 UrlEncode
1. 方法1
System.Web.HttpUtility.UrlEncode(taobao, Encoding.GetEncoding("gb2312"));
2. 方法2
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
public static string UrlEncode(string url, Encoding encoding)
{
StringBuilder sb = new StringBuilder();
byte[] bytes = encoding.GetBytes(url);
for (int i = 0; i < bytes.Length; i++)
{
sb.Append(@"%" + Convert.ToString(bytes[i], 16));
}
return (sb.ToString());
}
{
StringBuilder sb = new StringBuilder();
byte[] bytes = encoding.GetBytes(url);
for (int i = 0; i < bytes.Length; i++)
{
sb.Append(@"%" + Convert.ToString(bytes[i], 16));
}
return (sb.ToString());
}