asp.net对URL含有中文参数的转换
时间:2021-07-01 10:21:17
帮助过:50人阅读
代码如下:
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();
}