提交页面是ASP的GB2312编码格式,接收页面是ASP.net的UTF-8格式,如果不进行转换你就进行Request.QueryString["flag"]是只能得到英文字符的,而后的中文字符是会丢失的。解决方法是:
string CurrentStr = Request.Url.Query;
string CurrentStr = Request.Url.Query;
System.Collections.Specialized.NameValueCollection nv
= System.Web.HttpUtility.ParseQueryString(CurrentStr, System.Text.Encoding.GetEncoding
= System.Web.HttpUtility.ParseQueryString(CurrentStr, System.Text.Encoding.GetEncoding
("GB2312"));//这样便以GB2312编码格式进行解码
string flg= nv["flag"];
说明:
System.Web.HttpUtility.ParseQueryString 方法 (String, Encoding) 使用指定的 Encoding 将查询字符串分析成一个 NameValueCollection。
在返回的 NameValueCollection 中,URL 编码的字符将会进行解码,多次出现的同一查询字符串参数将单独列出,并使用逗号分隔每个值。
说明:
System.Web.HttpUtility.ParseQueryString 方法 (String, Encoding) 使用指定的 Encoding 将查询字符串分析成一个 NameValueCollection。
在返回的 NameValueCollection 中,URL 编码的字符将会进行解码,多次出现的同一查询字符串参数将单独列出,并使用逗号分隔每个值。
本文介绍了解决不同编码格式(GB2312与UTF-8)间网页数据传递时中文字符丢失的问题。通过使用HttpUtility.ParseQueryString方法并指定GB2312编码,可以确保从提交页面到接收页面的数据完整传输。
989

被折叠的 条评论
为什么被折叠?



