昨天我拿到某一公司的API说明文档:他会以get方式请求我公司网站上的指定接口(这个接口我正在做),
URL如下:"http://localhost/pages/ProcessRecord/XXX.aspx?uid=&name=&city=&address等N多参数,
并且中文用gb2312来编码!
好了,现在我要模拟这个get请求,好来做这个接口!比如A页面是请求页,B页面是接收页!
A页面代码如下: protected void Page_Load(object sender, EventArgs e)
{
      Response.Redirect(GetUrl());
}
protected string GetUrl()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("http://localhost/pages/ProcessRecord/B.aspx?");
        //省略了一大堆参数全是英文版的....
        sb.AppendFormat("&name={0}", HttpUtility.UrlEncode("姓名", Encoding.GetEncoding("gb2312")));
        sb.AppendFormat("&province={0}", HttpUtility.UrlEncode("广西", Encoding.GetEncoding("gb2312")));
        sb.AppendFormat("&city={0}", HttpUtility.UrlEncode("平南", Encoding.GetEncoding("gb2312")));
        sb.AppendFormat("&area={0}", HttpUtility.UrlEncode(string.Empty, Encoding.GetEncoding("gb2312")));
        sb.AppendFormat("&address={0}", HttpUtility.UrlEncode("广州市天河东", Encoding.GetEncoding("gb2312")));
        return sb.ToString();     }好了,现在在B页面处理了: protected void Page_Load(object sender, EventArgs e)
{
    string u = Request["name"].ToString();
    string uu = HttpUtility.UrlDecode(u, System.Text.Encoding.GetEncoding("gb2312"));   
    结果是u:����
          uu:����
}请问如何来处理请求过来的gb2312?
基本业务都写好代码了,就差这个gb2312编码的问题!

解决方案 »

  1.   

    把u 先按utf-8 做UrlEncode,在按GB2312做UrlDecode 试下
    或者该web.config requestEncoding="gb2312" 试试
      

  2.   

    HttpUtility.HtmlEncode换这个试试。
      

  3.   

    在<head></head>之间加这个代码:
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <meta http-equiv="Content-Language" content="zh-cn" />
      

  4.   

    把 web.config 的RequestEncoding="gb2312" 是可以的,我试了
      

  5.   

    把 web.config 的RequestEncoding="gb2312" 
     protected void Page_Load(object sender, EventArgs e)
    {
        string u = Request["name"].ToString();
        Response.Write(u);
    }
      

  6.   

    那这样吧,根据查询串自己处理
    string qs = Request.Url.Query;
    string encodeName = getQValue(qs,"name") //自己实现提取querystring中的值
    string u = HttpUtility.UrlDecode(encodeName, Encoding.GetEncoding("gb2312"))