您的位置:首页 > 其它

URL参数GB2312和UTF-8编码 自动识别

2013-12-12 11:59 351 查看
网上找的,以备后用。

直接上代码:

public static string QueryStringDecode(string key)
{
HttpRequest Request = System.Web.HttpContext.Current.Request;

if (Regex.IsMatch(
HttpUtility.UrlDecode(Request.Url.Query, Encoding.GetEncoding("iso-8859-1")),
@"^(?:[\x00-\x7f]|[\xfc-\xff][\x80-\xbf]{5}|[\xf8-\xfb][\x80-\xbf]{4}|[\xf0-\xf7][\x80-\xbf]{3}|[\xe0-\xef][\x80-\xbf]{2}|[\xc0-\xdf][\x80-\xbf])+$"
))
{
return Request.QueryString[key];
}
else
{
System.Collections.Specialized.NameValueCollection Rq = HttpUtility.ParseQueryString(Request.Url.Query, System.Text.Encoding.GetEncoding("gb2312"));
return Rq[key];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: