zoukankan      html  css  js  c++  java
  • 获取 Cookie

    /// <summary>
        /// 获取WPF url 地址中的Cookies
        /// </summary>
        public partial class CookieHelper
        {

            #region 获取所有的Cookies 数组
            /// <summary>
            /// 获取所有的Cookies 数组
            /// </summary>
            /// <param name="uri"></param>
            /// <returns></returns>
            public static Dictionary<string, string> GetCookies(Uri uri)
            {
                Dictionary<string, string> r_dictionary = new Dictionary<string, string>();
                string _str_cookies = Application.GetCookie(uri);
                string[] _cookiesArry = _str_cookies.Split(' ');
                foreach (var item in _cookiesArry)
                {
                    string _temp = item.Trim(';');
                    string[] _dictionary = _temp.Split('=');
                    r_dictionary.Add(_dictionary[0],_dictionary[1]);
                }
                return r_dictionary;
            }
            #endregion


            /// <summary>
            /// 设置Cookies
            /// </summary>
            /// <param name="uri"></param>
            /// <param name="name"></param>
            /// <param name="value"></param>
            /// <param name="expirationDate"></param>
            public static void SetCookie(Uri uri, String name, String value, DateTime expirationDate)
            {
                String cookie = String.Format("{0}={1}; expires={2}", name, value, GetExpirationDateString(expirationDate));
                Application.SetCookie(uri, cookie);
            }

            /// <summary>
            /// 获取Cookies
            /// </summary>
            /// <param name="uri"></param>
            /// <returns></returns>
            public static String GetCookie(Uri uri)
            {
                return Application.GetCookie(uri);
            }


            private static String GetExpirationDateString(DateTime expirationDate)
            {
                return expirationDate.ToString("ddd, dd-MMM-yyyy HH:mm:ss") + " GMT";
            }

  • 相关阅读:
    如何选择机器学习算法 转
    机器学习经典算法详解及Python实现--基于SMO的SVM分类器
    机器学习(Machine Learning)&深度学习(Deep Learning)资料
    计算智能在设备状态维护中的应用
    LaTeX 在编译时出现 File ended while scanning use of @writefile错误
    LaTeX 中插入图片使其紧跟插入的文字之后
    LaTeX 制作表格
    LaTeX 中换段落
    LaTeX 中使用三级标题
    使用 WinEdt 来写中文文章or 建模论文
  • 原文地址:https://www.cnblogs.com/jinhaoObject/p/5266022.html
Copyright © 2011-2022 走看看