现在的位置: 首页 > 综合 > 正文

怎样使用C#将unicode的编码转换为gb2312

2012年11月03日 ⁄ 综合 ⁄ 共 402字 ⁄ 字号 评论关闭

其实 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"));

 

抱歉!评论已关闭.