首页 > Windows开发 > 详细

获取WPF url 地址中的Cookies

时间:2020-02-25 16:38:13      阅读:24      评论:0      收藏:0      [点我收藏+]

标签:sta   get   res   post   rim   art   

/// <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";
        }

}

获取WPF url 地址中的Cookies

标签:sta   get   res   post   rim   art   

原文:https://www.cnblogs.com/changbaishan/p/12362193.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号