unicode怎么转gb2312

解决方案 »

  1.   

    http://www.google.com.hk/search?client=aff-cs-maxthon&channel=channel2&q=unicode%E6%80%8E%E4%B9%88%E8%BD%ACgb2312
      

  2.   

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

  3.   

    http://www.baidu.com/s?wd=unicode%D4%F5%C3%B4%D7%AAgb2312呵呵.自己看吧.
      

  4.   

    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());
                }
            }
      

  5.   

    上面代码中的 summery 写错了,你把它改成 summary
      

  6.   

    楼主你问的太宽泛了
    需要转换编码的情况很多,并不是每种情况都要改web.config文件或者httpheader来解决,你先说说你遇到的是什么状况啊