.....................unicode转gb2312 unicode怎么转gb2312 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.google.com.hk/search?client=aff-cs-maxthon&channel=channel2&q=unicode%E6%80%8E%E4%B9%88%E8%BD%ACgb2312 web.config中配置 <globalization requestEncoding="gb2312" responseEncoding="gb2312" /> <!--<pages validateRequest="false"/>--><httpRuntime maxRequestLength="20000"/>c# 代码Stream stream=Request.InputStream;StreamReader sr=new StreamReader(stream,Encoding.UTF8);string ss=sr.ReadToEnd();byte[] bs=Encoding.UTF8.GetBytes(ss);string cc=HttpUtility.UrlDecode(bs,0,bs.Length,Encoding.GetEncoding("GB2312")); http://www.baidu.com/s?wd=unicode%D4%F5%C3%B4%D7%AAgb2312呵呵.自己看吧. 3 楼就是正确了。给你扩展一下,把 GB2312 转 UTF-8 及相反方向的转码函数给你贴出来吧。原理都是一样的,先把输入的字符串转成字节数组,再按指定的编码方式输出。 ///<summery> ///将 UTF-8 编码字符串转为 GB2312 编码字符串 ///</summery> public string UTF8ToGB2312(string str) { try { Encoding utf8 = Encoding.GetEncoding(65001); Encoding gb2312 = Encoding.GetEncoding("gb2312");//Encoding.Default ,936 byte[] temp = utf8.GetBytes(str); byte[] temp1 = Encoding.Convert(utf8, gb2312, temp); string result = gb2312.GetString(temp1); return result; } catch (Exception ex)//(UnsupportedEncodingException ex) { throw new Exception(ex.ToString()); } } ///<summery> ///将 GB2312 编码字符串转为 UTF-8 编码字符串 ///</summery> public string GB2312ToUTF8(string str) { try { Encoding uft8 = Encoding.GetEncoding(65001); Encoding gb2312 = Encoding.GetEncoding("gb2312"); byte[] temp = gb2312.GetBytes(str); byte[] temp1 = Encoding.Convert(gb2312, uft8, temp); string result = uft8.GetString(temp1); return result; } catch (Exception ex)//(UnsupportedEncodingException ex) { throw new Exception(ex.ToString()); } } 上面代码中的 summery 写错了,你把它改成 summary 楼主你问的太宽泛了需要转换编码的情况很多,并不是每种情况都要改web.config文件或者httpheader来解决,你先说说你遇到的是什么状况啊 发送post实现自动登陆,需要登陆到页面而不是返回成功登陆的代码 异步发送邮件的问题,在线等~ 为什么我没有绑定回车事件按回车还会执行程序 asp.net中使用access数据库的疑问 广撒英雄贴!!!请教天下英雄,如何向Oracle中插入上万条数据!!!!!!在线等!!拜谢~~ 请高手指教!webform中 push型水晶报表的打印代码如何编写? 关于开发环境的问题 请高手教我如何使用freetextbox,急!!! 请高手赐教.net中的困惑。 新手提问:如何在网页上用中文? 关于CHECKBOX 颜色变灰,但还能选择 用JS判断浏览器???
<!--<pages validateRequest="false"/>-->
<httpRuntime
maxRequestLength="20000"
/>c# 代码
Stream stream=Request.InputStream;
StreamReader sr=new StreamReader(stream,Encoding.UTF8);
string ss=sr.ReadToEnd();
byte[] bs=Encoding.UTF8.GetBytes(ss);
string cc=HttpUtility.UrlDecode(bs,0,bs.Length,Encoding.GetEncoding("GB2312"));
原理都是一样的,先把输入的字符串转成字节数组,再按指定的编码方式输出。
///<summery>
///将 UTF-8 编码字符串转为 GB2312 编码字符串
///</summery>
public string UTF8ToGB2312(string str)
{
try
{
Encoding utf8 = Encoding.GetEncoding(65001);
Encoding gb2312 = Encoding.GetEncoding("gb2312");//Encoding.Default ,936
byte[] temp = utf8.GetBytes(str);
byte[] temp1 = Encoding.Convert(utf8, gb2312, temp);
string result = gb2312.GetString(temp1);
return result;
}
catch (Exception ex)//(UnsupportedEncodingException ex)
{
throw new Exception(ex.ToString());
}
}
///<summery>
///将 GB2312 编码字符串转为 UTF-8 编码字符串
///</summery>
public string GB2312ToUTF8(string str)
{
try
{
Encoding uft8 = Encoding.GetEncoding(65001);
Encoding gb2312 = Encoding.GetEncoding("gb2312");
byte[] temp = gb2312.GetBytes(str);
byte[] temp1 = Encoding.Convert(gb2312, uft8, temp);
string result = uft8.GetString(temp1);
return result;
}
catch (Exception ex)//(UnsupportedEncodingException ex)
{
throw new Exception(ex.ToString());
}
}
需要转换编码的情况很多,并不是每种情况都要改web.config文件或者httpheader来解决,你先说说你遇到的是什么状况啊