zoukankan      html  css  js  c++  java
  • Cookie值中文乱码问题

    cookie里面不能写中文,是由于cookie先天的编码方式造成的。所以需要有一种中间编码来过渡。 URLEncode是最好的选择。

    我们以asp.net为例,代码如下:

    设置Cookie时:

    HttpCookie cookie = new HttpCookie("name", System.Web.HttpContext.Current.Server.UrlEncode("雨林星空"));
    Response.Cookies.Add(cookie);

    读取Cookie时:

    if (Request.Cookies["name"] != null)
    {
        Response.Write(System.Web.HttpContext.Current.Server.UrlDecode(Request.Cookies["name"].Value));
    }
    
    

    注意:编码和解码要一致

    System.Web.HttpContext.Current.Server.UrlDecode 和 System.Web.HttpContext.Current.Server.UrlEncode

    System.Web.HttpUtility.UrlDecode 和 System.Web.HttpUtility.UrlEncode

  • 相关阅读:
    (QR14)带权的DAG节点排序
    数字组合
    最长连续不重复子序列
    树状数组
    归并排序
    差分
    前缀和
    64位整数乘法
    MySQL8 常用指令
    离线及实时实操架构
  • 原文地址:https://www.cnblogs.com/codeloves/p/2914057.html
Copyright © 2011-2022 走看看