asp.net接收页面使用get传递参数,querystring中使用gb2312 url编码,接收页面响应默认的是utf-8格式.这样通过request.querystring获取参数时,汉字就是乱码,请问怎样将这些乱码还原?

解决方案 »

  1.   

    发送时Server.UrlEncode("中文"),接收时Server.UrlDecode获取
      

  2.   

    为啥搞那么复杂,直接用Server.UrlEecode()和Server.UrlDecode()进行编码和还原行不行?
      

  3.   

    你不需要理会querystring里面的编码规则,除非是你有意这么做。
      

  4.   

    在 asp.net 中 Request.QueryString 只能识别 gb2312 编码的汉字 
    对于用 utf8 编码的参数可以从 RawUrl 中分解出查询参数然后对其解码获得,例如:
    dim bytes() as byte = HttpUtility.UrlDecodeToBytes("%e7%8e%8b%e7%8e%8b%e7%8e%8b") 
    dim text as string  = HttpUtility.UrlDecode(bytes,Encoding.UTF8)
      

  5.   

    使用以下方法获取不同编码的请求:
    HttpUtility.ParseQueryString(Request.Url.Query, Encoding.Default)["xmldata"]