现在要两个网站对接,对方是用GB2312,我们自已用的是UTF-8,我们网站的web.config中
    <!--  全球化          此节设置应用程序的全球化设置。    -->
    <globalization 
            requestEncoding="utf-8" 
            responseEncoding="utf-8" 
   />
如果是这样的话,就不能接收对方传来值,如果改成
 <!--  全球化          此节设置应用程序的全球化设置。    -->
    <globalization 
            requestEncoding="GB2312" 
            responseEncoding="GB2312" 
   />
就可以了,但这样话,很多网页显示将会有问题,很多。要对方把GB2312改成utf-8要收费,更重要的是还很慢。在不改web.config的情况下,传数字与字母没问题,传汉字就有问题了。
url形如:url="http://demoair.abc.com/b2c/Interface/UserReg_UTF8.aspx?RId=123&[email protected]&Mobile=13245463733&Password=11111111&PasswordQuestion=1&PasswordAnswer=1&CustomerName=测试&Sex=男&Province=北京&City=北京&Address=海淀&CertificateType=0&IdNum=220292123338383383&Phone=28377372&PostalCode=132001"
问题:不改web.config怎么接收对方通过url传过来的值,而且是GB2312的。

解决方案 »

  1.   

    实际测试时url不会有汉字,都是进行编码的
      

  2.   

    应是这样的:http://demoair.abc.com/b2c/Interface/UserReg.aspx?RId=974&[email protected]&Mobile=13812589632&CustomerName=%e5%bc%a0%e5%a4%a9%e5%81%a5&Sex=%e7%94%b7&Phone=021641888%ef%bc%8d8021
      

  3.   

    这样的Url传递应该都可以获取啊
      

  4.   

    试试给汉字编码:...&CustomerName=System.Web.HttpUtility.UrlEncode("测试",System.Text.Encoding.GetEncoding("gb2312"));
      

  5.   

    我这边用两种编码格式的网页都测试了一下Request.QueryString["CustomerName"]的值都 是张天健
      

  6.   

    应是这样的:http://demoair.abc.com/b2c/Interface/UserReg.aspx?RId=974&[email protected]&Mobile=13812589632&CustomerName=%e5%bc%a0%e5%a4%a9%e5%81%a5&Sex=%e7%94%b7&Phone=021641888%ef%bc%8d8021这个已经编码了,应该可以正确获取.CustomerName=测试, 这种不行!
      

  7.   

    这种传应该没问题呀.都是英文字符了.
    Server.UrlDecode(),做了一个测试webconfig
    <?xml version="1.0"?>
    <!-- 
        注意: 除了手动编辑此文件以外,您还可以使用 
        Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
         “网站”->“Asp.Net 配置”选项。
        设置和注释的完整列表在 
        machine.config.comments 中,该文件通常位于 
        \Windows\Microsoft.Net\Framework\v2.x\Config 中
    -->
    <configuration>
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <globalization 
                requestEncoding="utf-8" 
                responseEncoding="utf-8" 
      />    <httpHandlers>
        </httpHandlers>
    </system.web>
    </configuration>
    default.aspx代码很简单
      Response.Write(Request.Params["CustomerName"]);
    传递的urlhttp://localhost:88/Default.aspx?CustomerName=%e5%bc%a0%e5%a4%a9%e5%81%a5&Sex=%e7%94%b7&Phone=021641888%ef%bc%8d8021结果张天健 
      

  8.   

    嗯.其实,如果不改gb2312
    只是说reqeust的时候不认识url 中的http://localhost:88/Default.aspx?CustomerName=张天健&Sex=%e7%94%b7&Phone=021641888%ef%bc%8d8021 中文字符而已,和接收值没什么影响是不是有可能你上面没有装gb2312的字体,或是其它原因
      

  9.   

    大家误解了,不是这样的,我传给对方的时候
    this.Response.Redirect(ConfigurationSettings.AppSettings["YeePayURL"]+"b2c/Interface/UserReg.aspx?RId="+RID+"&Email="+this.txtMail.Value.Trim()+"&Mobile="+this.txtMobile.Value.Trim()+"&CustomerName="+this.txtName.Value.Trim()+"&Sex="+this.drpSex.SelectedItem.Text+"&Phone="+this.txtPhone.Value.Trim()+"&Password="+this.txtPWD1.Value.Trim(),true);这时网站会自动按照web.config
     <!--  全球化          此节设置应用程序的全球化设置。    --> 
        <globalization 
                requestEncoding="utf-8" 
                responseEncoding="utf-8" 
      /> 
    下的这个进行编码。也就进行了utf-8进行了编码。但是这样的话,对方不能接收到传的汉字
      

  10.   

    看看能否通过使用escape来解决楼主的问题,具体请参看:
    http://www.cnblogs.com/dnawo/archive/2007/12/27/1016241.html
      

  11.   

    所有内容都手工编码,比如
    Server.UrlEncode(this.txtMail.Value.Trim())
      

  12.   

    url="http://demoair.abc.com/b2c/Interface/UserReg_UTF8.aspx?RId=123&Email [email protected]&Mobile=13245463733&Password=11111111&PasswordQuestion =1&PasswordAnswer=1&CustomerName=测试&Sex=男&Province=北京 &City=北京&Address=海淀&CertificateType=0&IdNum= 220292123338383383&Phone=28377372&PostalCode=132001"
    这种url是非法的,只有很特殊的情况下服务器才可以解释,
    在url标准里,“测试”这种中文字符是不应该存在的,有的只能是%e5%bc这样形式的编码。
    可以使用Server.UrlEncode来对参数进行编码