现在要两个网站对接,对方是用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的。
<!-- 全球化 此节设置应用程序的全球化设置。 -->
<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的。
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结果张天健
只是说reqeust的时候不认识url 中的http://localhost:88/Default.aspx?CustomerName=张天健&Sex=%e7%94%b7&Phone=021641888%ef%bc%8d8021 中文字符而已,和接收值没什么影响是不是有可能你上面没有装gb2312的字体,或是其它原因
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进行了编码。但是这样的话,对方不能接收到传的汉字
http://www.cnblogs.com/dnawo/archive/2007/12/27/1016241.html
Server.UrlEncode(this.txtMail.Value.Trim())
这种url是非法的,只有很特殊的情况下服务器才可以解释,
在url标准里,“测试”这种中文字符是不应该存在的,有的只能是%e5%bc这样形式的编码。
可以使用Server.UrlEncode来对参数进行编码