復制代碼 代碼如下:
protected string UrlEncode(string url)
...{
byte[] bs = Encoding.GetEncoding("GB2312").GetBytes(url);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bs.Length; i++)
...{
if (bs[i] < 128)
sb.Append((char)bs[i]);
else
...{
sb.Append("%" + bs[i++].ToString("x").PadLeft(2, '0'));
sb.Append("%" + bs[i].ToString("x").PadLeft(2, '0'));
}
}
return sb.ToString();
}